mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-12-26 23:21:18 +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.
|
// Init permutations array.
|
||||||
const permutations = [];
|
const permutations = [];
|
||||||
|
|
||||||
// Go through all options and join it to the smaller permutations.
|
// Get smaller permutations.
|
||||||
permutationOptions.forEach((currentOption) => {
|
|
||||||
const smallerPermutations = permutateWithRepetitions(
|
const smallerPermutations = permutateWithRepetitions(
|
||||||
permutationOptions,
|
permutationOptions,
|
||||||
permutationLength - 1,
|
permutationLength - 1,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Go through all options and join it to the smaller permutations.
|
||||||
|
permutationOptions.forEach((currentOption) => {
|
||||||
smallerPermutations.forEach((smallerPermutation) => {
|
smallerPermutations.forEach((smallerPermutation) => {
|
||||||
permutations.push([currentOption].concat(smallerPermutation));
|
permutations.push([currentOption].concat(smallerPermutation));
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user