MCPcopy Create free account
hub / github.com/TanStack/devtools / getAllPermutations

Function getAllPermutations

packages/devtools/src/utils/sanitize.ts:13–30  ·  view source on GitHub ↗
(arr: Array<T>)

Source from the content-addressed store, hash-verified

11 value.charAt(0).toUpperCase() + value.slice(1)
12
13export const getAllPermutations = <T extends any>(arr: Array<T>) => {
14 const res: Array<Array<T>> = []
15
16 function permutate(arr: Array<T>, start: number) {
17 if (start === arr.length - 1) {
18 res.push([...arr] as any)
19 return
20 }
21 for (let i = start; i < arr.length; i++) {
22 ;[arr[start], arr[i]] = [arr[i]!, arr[start]!]
23 permutate(arr, start + 1)
24 ;[arr[start], arr[i]] = [arr[i]!, arr[start]]
25 }
26 }
27 permutate(arr, 0)
28
29 return res
30}

Callers 2

getHotkeyPermutationsFunction · 0.90
sanitize.test.tsFile · 0.90

Calls 1

permutateFunction · 0.85

Tested by

no test coverage detected