Created
March 20, 2016 04:15
-
-
Save pablocortez/82628e6cf73fbe20bdaa to your computer and use it in GitHub Desktop.
A breakdown of an elegant Fizzbuzz solution.
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
// Expanded version | |
for (var i = 1; i < 100; i++) { | |
var f = i % 3 == 0, b = i % 5 == 0; | |
if (f) { | |
if (b) { | |
console.log("Fizzbuzz") | |
} else { | |
console.log("Fizz"); | |
} | |
} else if (b) { | |
console.log("Buzz"); | |
} else { | |
console.log(i); | |
} | |
} | |
// Condensed solution | |
for (var i = 1; i < 100; i++) { | |
var f = i % 3 == 0, b = i % 5 == 0; | |
console.log(f ? b ? "Fizzbuzz" : "Fizz" : b ? "Buzz" : i); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment