Skip to content

Commit 1831d39

Browse files
committed
feat(permutations): updato to make code more readable by using default parameter
1 parent 1e8c8f2 commit 1831d39

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

16_permutations/solution/permutations-solution.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
const permutations = function (original, currentPermutations = original.map((num) => [num])) {
2-
if (original.length === 0) return [];
3-
if (original.length === 1) return [original];
1+
const permutations = function (
2+
original,
3+
currentPermutations = original.map((num) => [num]),
4+
) {
5+
if (original.length < 2) return [original];
46

57
const newPerms = [];
6-
perms.forEach((el) => {
8+
currentPermutations.forEach((el) => {
79
const missing = original.filter((item) => !el.includes(item));
810
missing.forEach((itemMissing) => newPerms.push([...el, itemMissing]));
911
});

0 commit comments

Comments
 (0)