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

Function transferArrayItem

src/cdk/drag-drop/drag-utils.ts:40–52  ·  view source on GitHub ↗
(
  currentArray: T[],
  targetArray: T[],
  currentIndex: number,
  targetIndex: number,
)

Source from the content-addressed store, hash-verified

38 * @param targetIndex Index at which to insert the item.
39 */
40export function transferArrayItem<T = any>(
41 currentArray: T[],
42 targetArray: T[],
43 currentIndex: number,
44 targetIndex: number,
45): void {
46 const from = clamp(currentIndex, currentArray.length - 1);
47 const to = clamp(targetIndex, targetArray.length);
48
49 if (currentArray.length) {
50 targetArray.splice(to, 0, currentArray.splice(from, 1)[0]);
51 }
52}
53
54/**
55 * Copies an item from one array to another, leaving it in its

Callers 2

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

Calls 1

clampFunction · 0.70

Tested by

no test coverage detected