-
-
Save snewcomer/14b40d99fae0e44e090fce5370a3139f to your computer and use it in GitHub Desktop.
getBooleanTable
This file contains hidden or 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 getBooleanTable = number => Array(Math.pow(2, number)) | |
.fill() | |
.map((_, idx) => idx) | |
.map(num => num.toString(2).padStart(number, '0')) | |
.map(stringOfBits => | |
stringOfBits.split('').map(bit => Boolean(parseInt(bit))) | |
) | |
console.log(getBooleanTable(3)) | |
// [ | |
// [false, false, false], | |
// [false, false, true], | |
// [false, true, false], | |
// [false, true, true], | |
// [true, false, false], | |
// [true, false, true], | |
// [true, true, false], | |
// [true, true, true] | |
// ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment