Heap's Algorithm
To generate all permutations of an array
var perm_arr = [];
// fill the array with numbers from 1 to 7
for (let i = 1; i <= 7; i++) {
perm_arr.push(i);
}
// Returns an array with all the permutations
console.log(permutations(perm_arr));
Note
As the length of the array increases the number of permutations increases exponentially.