Created
October 10, 2022 21:27
-
-
Save 0ex-d/acb3ba2ea9fc60223850998f8f6183b4 to your computer and use it in GitHub Desktop.
🥹 My top Longest Short-Circuit Evaluation in Javascript and Rust.
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
// use good 'ol c-language one-liner (rust doesn't have terniary operator 🙂) | |
let x = if true { if false { true } else { false } } else { if true { false } else { true } }; | |
// could also be | |
let x = if true { !false } else { !true }; | |
// even further | |
let x = if true { true } else { false }; |
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
// quick short-circuit | |
let x = if (true) { | |
if (false) { true } else { false } | |
} else { | |
if (true) { false } else { true } | |
}; |
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
// exhaustive matching (or None) | |
match (a, b) { | |
(true, true) => ..., | |
(true, false) => ..., | |
(false, true) => ..., | |
(false, false) => ..., | |
_ => ... | |
} |
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
// Javascript has terniary operator, could be good or could also get out of hand | |
let x = true ? false ? true : false : true ? false : true; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment