@@ -13,15 +13,30 @@ function createProjectWithFeatureFlags(flags) {
13
13
14
14
const featureFlags = [ 'typescript' , 'jsx' , 'router' , 'vuex' , 'with-tests' ]
15
15
16
- // FIXME: not correct
17
16
function getCombinations ( arr ) {
18
17
const combinations = [ ]
19
18
20
- for ( let i = 0 ; i < arr . length ; i ++ ) {
21
- for ( let j = i ; j < arr . length ; j ++ ) {
22
- const combination = arr . slice ( i , j + 1 )
23
- combinations . push ( combination )
19
+ // The following code & comments are generated by GitHub CoPilot.
20
+
21
+ // for an array of 5 elements, there are 2^5 - 1= 31 combinations
22
+ // (excluding the empty combination)
23
+ // equivalent to the following:
24
+ // [0, 0, 0, 0, 1] ... [1, 1, 1, 1, 1]
25
+ // We can represent the combinations as a binary number
26
+ // where each digit represents a flag
27
+ // and the number is the index of the flag
28
+ // e.g.
29
+ // [0, 0, 0, 0, 1] = 0b0001
30
+ // [1, 1, 1, 1, 1] = 0b1111
31
+
32
+ for ( let i = 1 ; i < 1 << arr . length ; i ++ ) {
33
+ const combination = [ ]
34
+ for ( let j = 0 ; j < arr . length ; j ++ ) {
35
+ if ( i & ( 1 << j ) ) {
36
+ combination . push ( arr [ j ] )
37
+ }
24
38
}
39
+ combinations . push ( combination )
25
40
}
26
41
27
42
return combinations
0 commit comments