Open History to see the last commit
1export function moveTask<T>(
2 columnTasks: T[],
3 oldIndex: number,
4 newIndex: number,
5): T[] {
6 const newColumnTasks = columnTasks.slice(); // Copy array
7 if (oldIndex < 0 || oldIndex >= newColumnTasks.length) return newColumnTasks;
8 let targetIndex = newIndex;
9 if (oldIndex < newIndex) targetIndex--;
10 const [item] = newColumnTasks.splice(oldIndex, 1);
11 newColumnTasks.splice(targetIndex, 0, item);
12 return newColumnTasks;
13}