jws-frontend/src/utils/arr.ts
2024-10-30 11:30:44 +07:00

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;