Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 59c6f4d

Browse files
committed
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‎

Lines changed: 6 additions & 5 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /