This is an implementation of Heap's algorithm (similar to @le_m's), except it's recursive.
function permute_kingzee(arr,n=arr.length,out=[]) {
if(n == 1) {
return out.push(arr.slice());
} else {
for(let i=0; i
It looks like it's quite faster too : https://jsfiddle.net/3brqzaLe/