We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 54a63d9 commit ef46c3eCopy full SHA for ef46c3e
bit-combinations.js
@@ -1,18 +1,15 @@
1
-const combinations = (n) => {
2
- if (n == 0) {
3
- result.push(combination);
4
- return;
+const printBinary = (n, result) => {
+ if (n === 0) {
+ console.log(result)
+ }
5
+ else {
6
+ result = result.concat(0);
7
+ printBinary(n - 1, result);
8
+ // unchoose 0; and choose 1
9
+ result = result.slice(0, result.length - 1);
10
+ result = result.concat(1);
11
12
}
- combination = combination.concat(0);
- combinations(n - 1);
- combination = combination.slice(0, combination.length - 1);
- combination = combination.concat(1);
13
14
-const n = 2;
15
-const result = [];
16
-let combination = [];
17
-combinations(n);
18
-console.log(result);
+printBinary(3, []);
0 commit comments