15 lines
406 B
TypeScript
15 lines
406 B
TypeScript
const arr = { move, removeAt, insertAt };
|
|
|
|
export function move<T extends any>(arr: T[], idx: number, offset: number) {
|
|
arr.splice(idx + offset, 0, ...arr.splice(idx, 1));
|
|
}
|
|
|
|
export function removeAt<T extends any>(arr: T[], idx: number) {
|
|
return arr.splice(idx, 1);
|
|
}
|
|
|
|
export function insertAt<T extends any>(arr: T[], idx: number, item: T) {
|
|
return arr.splice(idx, 0, item);
|
|
}
|
|
|
|
export default arr;
|