MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / permute

Function permute

src/common/utils.ts:51–64  ·  view source on GitHub ↗
(arr: T[], m: T[] = [])

Source from the content-addressed store, hash-verified

49 const result: ReadonlyArray<T>[] = [];
50
51 const permute = (arr: T[], m: T[] = []) => {
52 if (arr.length === 0) {
53 if (!condition || condition(m)) {
54 // Use spread operator to create a shallow copy of m
55 result.push([...m]);
56 }
57 } else {
58 for (let i = 0; i < arr.length; i++) {
59 const curr = arr.slice();
60 const next = curr.splice(i, 1);
61 permute(curr.slice(), m.concat(next));
62 }
63 }
64 };
65
66 //@fix: (typing)
67 permute(xs as T[]);

Callers 1

permutationsFunction · 0.70

Calls 1

sliceMethod · 0.65

Tested by

no test coverage detected