mirror of
https://github.com/swc-project/swc.git
synced 2024-12-21 20:51:42 +03:00
c0e72ef64a
**Related issue:** - Closes https://github.com/swc-project/swc/issues/6864.
30 lines
697 B
JavaScript
30 lines
697 B
JavaScript
export function removeFromMatrix(matrix, id) {
|
|
var newMatrix;
|
|
var indexOfIdToRemove;
|
|
|
|
var row = _.find(matrix, (entry, index) => {
|
|
if (_.includes(entry, id)) {
|
|
indexOfIdToRemove = index;
|
|
return entry;
|
|
}
|
|
});
|
|
|
|
if (!row) {
|
|
return matrix;
|
|
}
|
|
|
|
if (row.length === 1) {
|
|
newMatrix = _.without(matrix, row);
|
|
|
|
if (newMatrix[0].length === 2) {
|
|
const remainingEntry = newMatrix[0];
|
|
newMatrix = [[remainingEntry[0]], [remainingEntry[1]]];
|
|
}
|
|
} else {
|
|
newMatrix = [...matrix];
|
|
newMatrix[indexOfIdToRemove] = _.without(row, id);
|
|
}
|
|
|
|
return newMatrix || matrix;
|
|
}
|