Last active
September 29, 2018 17:53
-
-
Save edwingustafson/74a8473019e755b2389e49da317c212e to your computer and use it in GitHub Desktop.
Don't branch just to return a boolean
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
// This works but requires four lines of code | |
function wrong() { | |
if (Math.random() > 0.5) | |
return true | |
else | |
return false; | |
} | |
// Same result in a single line of code | |
function right() { | |
return Math.random() > 0.5; | |
} | |
// Even more compact if arrow notation available | |
const f = () => Math.random() > 0.5; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment