MCPcopy
hub / github.com/clauderic/dnd-kit / arraySwap

Function arraySwap

packages/helpers/src/move.ts:30–46  ·  view source on GitHub ↗
(
  array: T,
  from: number,
  to: number
)

Source from the content-addressed store, hash-verified

28 * Swap two array items with each other. Returns a new array with the two items at `from` and `to` exchanged in place.
29 */
30export function arraySwap<T extends any[]>(
31 array: T,
32 from: number,
33 to: number
34): T {
35 if (from === to) {
36 return array;
37 }
38
39 const newArray = array.slice() as T;
40 const item = newArray[from];
41
42 newArray[from] = newArray[to];
43 newArray[to] = item;
44
45 return newArray;
46}
47
48type Items = UniqueIdentifier[] | {id: UniqueIdentifier}[];
49

Callers 1

move.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected