MCPcopy Index your code
hub / github.com/TheAlgorithms/JavaScript / permutations

Function permutations

Backtracking/GeneratePermutations.js:20–34  ·  view source on GitHub ↗
(arr)

Source from the content-addressed store, hash-verified

18}
19
20const permutations = (arr) => {
21 const P = []
22 const permute = (arr, low, high) => {
23 if (low === high) {
24 P.push([...arr])
25 return P
26 }
27 for (let i = low; i <= high; i++) {
28 arr = swap(arr, low, i)
29 permute(arr, low + 1, high)
30 }
31 return P
32 }
33 return permute(arr, 0, arr.length - 1)
34}
35
36export { permutations }

Callers 1

Calls 1

permuteFunction · 0.85

Tested by

no test coverage detected