Last active
September 8, 2019 19:16
-
-
Save stvnrynlds/304c012e1121ed57109b0598d4aab8e9 to your computer and use it in GitHub Desktop.
world's teeniest fizzbuzz
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
(()=>{i=0;while(i<100)console.log((++i%3?'':'Fizz')+(i%5?'':'Buzz')||i)})() | |
// EXPLANATION | |
(() => { // Declare our anonymous FizzBuzz function | |
i = 0; // Set incrementor variable | |
while (i < 100) // While incrementor is less than 100, keep running the following: | |
console.log( // Log the following to the console: | |
// Increment i and get remainder of i/3. If remainder is 0 (falsy), return ''. If not-0 return 'Fizz'. | |
(++i % 3 ? '' : 'Fizz') | |
// Concatenate string '' or 'Fizz' with the results of the next expression | |
+ | |
// Get remainder of modulus of i/5. If remainder is 0, return ''. If not-0 return 'Buzz' | |
(i % 5 ? '' : 'Buzz') | |
// If both of the previous expressions are empty strings, return the integer | |
|| i | |
) | |
} | |
)() // Immediately invoke the function. | |
// See: http://stackoverflow.com/questions/2421911/what-is-the-purpose-of-wrapping-whole-javascript-files-in-anonymous-functions-li |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment