Created
August 8, 2021 15:48
-
-
Save brainfoolong/4c30bdf9d94acfa4d2f61f0ae932ef71 to your computer and use it in GitHub Desktop.
BitMask Demo
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
let CUTE = 1 | |
let ANGRY = 2 | |
let HUNGRY = 4 | |
let CAT = ANGRY | HUNGRY | |
// angry only would be: let CAT = ANGRY | |
// cute, angry and hungry would be: let CAT = CUTE | ANGRY | HUNGRY | |
if (CAT & HUNGRY) { | |
console.log('Yeah my cat is hungry') | |
if (CAT & ANGRY) { | |
console.log('And he\'s angry') | |
if (CAT & CUTE) { | |
console.log('But it doesn\'t matter because he\'s cute') | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment