-
-
Save alcedoatthis/e9d6bbd1f2fb37825fd182af3240f41b 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
enum Flags { | |
A = 1 << 0, | |
B = 1 << 1, | |
C = 1 << 2, | |
} | |
// number means uint | |
const allowed = (flags: Flags[], flag: Flags): boolean => | |
(flags.reduce((p, c) => p | c) & flag) === flag | |
const allowedFlags = [Flags.B | Flags.C] | |
console.log(allowed(allowedFlags, Flags.A))// -> false | |
console.log(allowed(allowedFlags, Flags.B))// -> true | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment