(array: T[], fromIndex: number, toIndex: number)
| 13 | * @param toIndex Index to which the item should be moved. |
| 14 | */ |
| 15 | export function moveItemInArray<T = any>(array: T[], fromIndex: number, toIndex: number): void { |
| 16 | const from = clamp(fromIndex, array.length - 1); |
| 17 | const to = clamp(toIndex, array.length - 1); |
| 18 | |
| 19 | if (from === to) { |
| 20 | return; |
| 21 | } |
| 22 | |
| 23 | const target = array[from]; |
| 24 | const delta = to < from ? -1 : 1; |
| 25 | |
| 26 | for (let i = from; i !== to; i += delta) { |
| 27 | array[i] = array[i + delta]; |
| 28 | } |
| 29 | |
| 30 | array[to] = target; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Moves an item from one array to another. |
no test coverage detected