MCPcopy Create free account
hub / github.com/angular/components / moveItemInArray

Function moveItemInArray

src/cdk/drag-drop/drag-utils.ts:15–31  ·  view source on GitHub ↗
(array: T[], fromIndex: number, toIndex: number)

Source from the content-addressed store, hash-verified

13 * @param toIndex Index to which the item should be moved.
14 */
15export 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.

Callers 11

dropMethod · 0.90
dropMethod · 0.90
dropMethod · 0.90
dropMethod · 0.90
dropMethod · 0.90
drag-utils.spec.tsFile · 0.90
DraggableInDropZoneClass · 0.90
sortMethod · 0.90
sortMethod · 0.90

Calls 1

clampFunction · 0.70

Tested by

no test coverage detected