MCPcopy
hub / github.com/tinyplex/tinybase / permute

Function permute

test/unit/core/store/mergeable-store.test.ts:19–30  ·  view source on GitHub ↗
(arr: any[])

Source from the content-addressed store, hash-verified

17const [reset, getNow, pause] = getTimeFunctions();
18
19const permute = (arr: any[]): any[] => {
20 if (arr.length == 1) {
21 return [arr[0]];
22 }
23 const permutations: any[] = [];
24 arr.forEach((item, i) =>
25 permute([...arr.slice(0, i), ...arr.slice(i + 1)]).forEach((other) =>
26 permutations.push([item, other].flat()),
27 ),
28 );
29 return permutations;
30};
31
32beforeEach(() => {
33 reset();

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…