jws-frontend/src/utils/arr.ts

16 lines
406 B
TypeScript
Raw Normal View History

2024-10-30 11:30:44 +07:00
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) {
2024-10-30 09:32:03 +07:00
return arr.splice(idx, 1);
}
2024-10-30 11:30:44 +07:00
export function insertAt<T extends any>(arr: T[], idx: number, item: T) {
2024-10-30 09:32:03 +07:00
return arr.splice(idx, 0, item);
}
2024-10-30 11:30:44 +07:00
export default arr;