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.
23 lines
708 B
JavaScript
23 lines
708 B
JavaScript
export function removeFromMatrix(matrix, id) {
|
|
var newMatrix, indexOfIdToRemove, row = _.find(matrix, (entry, index)=>{
|
|
if (_.includes(entry, id)) return indexOfIdToRemove = index, entry;
|
|
});
|
|
if (!row) return matrix;
|
|
if (1 === row.length) {
|
|
if (2 === (newMatrix = _.without(matrix, row))[0].length) {
|
|
const remainingEntry = newMatrix[0];
|
|
newMatrix = [
|
|
[
|
|
remainingEntry[0]
|
|
],
|
|
[
|
|
remainingEntry[1]
|
|
]
|
|
];
|
|
}
|
|
} else (newMatrix = [
|
|
...matrix
|
|
])[indexOfIdToRemove] = _.without(row, id);
|
|
return newMatrix || matrix;
|
|
}
|