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

Function permutate

packages/devtools/src/utils/sanitize.ts:16–26  ·  view source on GitHub ↗
(arr: Array<T>, start: number)

Source from the content-addressed store, hash-verified

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

Callers 1

getAllPermutationsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected