Skip to content

Commit f87609f

Browse files
authored
Create bit-combinations.js
1 parent 323d5a5 commit f87609f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

bit-combinations.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const combinations = (n) => {
2+
if (n == 0) {
3+
result.push(combination);
4+
return;
5+
}
6+
combination = combination.concat(0);
7+
combinations(n - 1);
8+
combination = combination.slice(0, combination.length - 1);
9+
combination = combination.concat(1);
10+
combinations(n - 1);
11+
combination = combination.slice(0, combination.length - 1);
12+
}
13+
14+
const n = 2;
15+
const result = [];
16+
let combination = [];
17+
combinations(n);
18+
console.log(result);

0 commit comments

Comments
 (0)