Skip to content

Instantly share code, notes, and snippets.

@edwingustafson
Last active September 29, 2018 17:53
Show Gist options
  • Save edwingustafson/74a8473019e755b2389e49da317c212e to your computer and use it in GitHub Desktop.
Save edwingustafson/74a8473019e755b2389e49da317c212e to your computer and use it in GitHub Desktop.
Don't branch just to return a boolean
// 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