All checks were successful
Publish To Prod / deploy_and_publish (push) Successful in 35s
17 lines
492 B
JavaScript
17 lines
492 B
JavaScript
export function arrayMoveMutable(array, fromIndex, toIndex) {
|
|
const startIndex = fromIndex < 0 ? array.length + fromIndex : fromIndex;
|
|
|
|
if (startIndex >= 0 && startIndex < array.length) {
|
|
const endIndex = toIndex < 0 ? array.length + toIndex : toIndex;
|
|
|
|
const [item] = array.splice(fromIndex, 1);
|
|
array.splice(endIndex, 0, item);
|
|
}
|
|
}
|
|
|
|
export function arrayMoveImmutable(array, fromIndex, toIndex) {
|
|
array = [...array];
|
|
arrayMoveMutable(array, fromIndex, toIndex);
|
|
return array;
|
|
}
|