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

Function swap

Backtracking/GeneratePermutations.js:12–18  ·  view source on GitHub ↗
(arr, i, j)

Source from the content-addressed store, hash-verified

10 */
11
12const swap = (arr, i, j) => {
13 const newArray = [...arr]
14
15 ;[newArray[i], newArray[j]] = [newArray[j], newArray[i]] // Swapping elements ES6 way
16
17 return newArray
18}
19
20const permutations = (arr) => {
21 const P = []

Callers 1

permuteFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected