how to find all permutations of an array with javascript
function getArrayMutations(arr, perms = [], len = arr.length) {
if (len === 1) perms.push(arr.slice(0))
for (let i = 0; i < len; i++) {
getArrayMutations(arr, perms, len - 1)
len % 2 // parity dependent adjacent elements swap
? [arr[0], arr[len - 1]] = [arr[len - 1], arr[0]]
: [arr[i], arr[len - 1]] = [arr[len - 1], arr[i]]
}
return perms
}
Also in JavaScript:
- how to turn a number negative in javascript
- color text react native
- sweet alert js
- react native routes
- how to use flatlist keyextractor
- pass argument to event listener javascript
- lazy react
- javascript appendchild at index
- node js return json
- manifest.webmanifest example
- react replace all line breaks with br
- setinterval jquery
- sendfile express syntax
- debugger js
- javascript remover acentos
- node module export multiple functions
- javascript remove duplicate strings from array
- javascript on url anchor change event
- check if string contains substring javascript
- javascript loop over classlist
- momentjs docs
- json datetime
- openssl error Subject does not start with '/'
- how to change the font family using jquery