feat: add utils function for array

This commit is contained in:
Methapon Metanipat 2024-10-30 11:30:44 +07:00
parent 8e8e29941f
commit 19428bef81

View file

@ -1,11 +1,15 @@
export function removeAt<T extends any[]>(arr: T, idx: number) {
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[number],
) {
export function insertAt<T extends any>(arr: T[], idx: number, item: T) {
return arr.splice(idx, 0, item);
}
export default arr;