Created
July 24, 2019 12:44
-
-
Save norbornen/0565f353907d812ee1f24ba546d5f0fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const values = [1,2,null,3].map((x) => !!x || null); | |
const vlength = values.length; | |
let combinations = []; | |
for (let i = 0; i < vlength; i++) { | |
if (values[i]) { | |
let acc = []; | |
acc.push(new Array(vlength).fill(null).fill(true, i, i + 1)); | |
for (let j = vlength - 1; j > i; j--) { | |
if (values[j]) { | |
acc = acc.concat( | |
acc.map((x) => x.slice().fill(true, j, j + 1))); | |
} | |
} | |
combinations = combinations.concat(acc); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment