mirror of
https://github.com/Threnklyn/advent-of-code-go.git
synced 2026-06-07 12:45:10 +02:00
24 lines
479 B
JavaScript
24 lines
479 B
JavaScript
function makePerms(low, high) {
|
|
const digits = [];
|
|
for (let i = low; i <= high; i++) {
|
|
digits.push(i);
|
|
}
|
|
|
|
const allPerms = [];
|
|
|
|
function inner(digitsArr, perm = []) {
|
|
if (perm.length === 5) {
|
|
allPerms.push(perm);
|
|
} else {
|
|
digitsArr.forEach((digit, index) => {
|
|
inner(digitsArr.slice(0, index).concat(digitsArr.slice(index + 1)), perm.concat(digit))
|
|
})
|
|
}
|
|
}
|
|
|
|
inner(digits);
|
|
return allPerms;
|
|
}
|
|
|
|
console.log(makePerms(0, 4));
|