Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 59c6f4d

Browse files
committedDec 14, 2018
Optimize permutations algorithm.
1 parent d9946c1 commit 59c6f4d

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed
 

‎src/algorithms/sets/permutations/permutateWithRepetitions.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ export default function permutateWithRepetitions(
1414
// Init permutations array.
1515
const permutations = [];
1616

17+
// Get smaller permutations.
18+
const smallerPermutations = permutateWithRepetitions(
19+
permutationOptions,
20+
permutationLength - 1,
21+
);
22+
1723
// Go through all options and join it to the smaller permutations.
1824
permutationOptions.forEach((currentOption) => {
19-
const smallerPermutations = permutateWithRepetitions(
20-
permutationOptions,
21-
permutationLength - 1,
22-
);
23-
2425
smallerPermutations.forEach((smallerPermutation) => {
2526
permutations.push([currentOption].concat(smallerPermutation));
2627
});

0 commit comments

Comments
 (0)
Please sign in to comment.