Last active
April 28, 2020 02:03
-
-
Save resynth1943/6636747d1f350f304372f780ffe91b8c to your computer and use it in GitHub Desktop.
Tiny 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
for ( | |
let /* index */ i = 0, | |
/* Buzz */ x, | |
/* Fizz */ y, | |
/* Buzz string */ l, | |
/* Empty string constant */ v = "", | |
/* Fizz string */ m, | |
/* Destructed the `console` for shorter code: */ { log: K } = console; | |
/* We need to do the FizzBuzz calculation 100 times. */ i <= 100; | |
/* And, of course, increment the index each time. Just a normal `for` loop so far. */ i++ | |
) | |
/* This variable tells us whether or not this number is a `Buzz` number */ (x = !(i % 5)), | |
/* This variable contains whether or not this number is a `Fizz` number */ (y = !(i % 3)), | |
/* Then, we turn that into a string if it's a `Buzz` number (notice the ternary) */ (l = x ? "Buzz" : v /* Or, we just use our empty string constant defined above */), | |
/* Same as the above, but for `Fizz` */ (m = y ? "Fizz" : v), | |
/* Then we pass them to the logger. If both `Fizz` and `Buzz` strings are empty, it's obviously neither `Fizz` nor `Buzz`. In that case, print out the index instead. */ K(m + l || i); |
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
for(let i=0,x,y,l,v='',m,{log:K}=console;i<=100;i++)x=!(i%5),y=!(i%3),l=x?'Buzz':v,m=y?'Fizz':v,K(m+l||i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment