We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f87609f commit 7eee706Copy full SHA for 7eee706
permutations.js
@@ -0,0 +1,18 @@
1
+const permute = (rest) => {
2
+ if(!rest.length) {
3
+ permutations.push(permutation.join(""));
4
+ return;
5
+ }
6
+ for (let i = 0; i < rest.length; i++) {
7
+ permutation = permutation.concat(rest[i]);
8
+ permute(rest.split("").filter(c => c !== rest[i]).join(""));
9
+ permutation = permutation.slice(0, permutation.length - 1);
10
11
12
+
13
+ let permutations = [];
14
+ let permutation = [];
15
+ const input = "abc";
16
+ permute(input);
17
+ console.log(permutations);
18
0 commit comments