What i wanted to do was take an array of integers and get all permutations of that array keeping the same length. I was using the array [1,2,3,4,5] after trying for a bit i just decided to do it the hard way. However im sure there is a better way. If you’ve ever done this before I’d love to see how you did it. This is how i did it in an ugly non scalable way.
let nums = [1,2,3,4,5];
let perms = [];
function permutate(arr){
for(let i = 0; i < arr.length; i++){
for(let j = 0; j < arr.length; j++){
for(let k = 0; k < arr.length; k++){
for(let l = 0; l < arr.length; l++){
for(let m = 0; m < arr.length; m++){
if(i != j && i != k && i != l && i != m && j != k && j != l && j != m && k != l && k != m && l != m){
let newArr = [arr[i],arr[j],arr[k],arr[l],arr[m]];
perms.push(newArr);
}
}
}
}
}
}
}
permutate(nums);