mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-12-26 15:11:16 +08:00
Optimize permutations algorithm.
This commit is contained in:
parent
d9946c1249
commit
59c6f4df13
@ -14,13 +14,14 @@ export default function permutateWithRepetitions(
|
||||
// Init permutations array.
|
||||
const permutations = [];
|
||||
|
||||
// Get smaller permutations.
|
||||
const smallerPermutations = permutateWithRepetitions(
|
||||
permutationOptions,
|
||||
permutationLength - 1,
|
||||
);
|
||||
|
||||
// Go through all options and join it to the smaller permutations.
|
||||
permutationOptions.forEach((currentOption) => {
|
||||
const smallerPermutations = permutateWithRepetitions(
|
||||
permutationOptions,
|
||||
permutationLength - 1,
|
||||
);
|
||||
|
||||
smallerPermutations.forEach((smallerPermutation) => {
|
||||
permutations.push([currentOption].concat(smallerPermutation));
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user