Last active
December 11, 2015 14:18
-
-
Save vstarck/4613064 to your computer and use it in GitHub Desktop.
FizzBuzz without conditional / boolean operators / trycatch / etc
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
function fizzBuzz(from, to) { | |
function print() { | |
var text = | |
'Fizz,,'.split(',')[from%3] + | |
'Buzz,,,,'.split(',')[from%5] | |
var _ = {} | |
_[text] = '' | |
_[''] = from | |
console.log( | |
from, ' -> ', text + _[text] | |
) | |
} | |
function next() { | |
var _ = {} | |
_[from] = loop | |
_[to] = function() {} | |
_[from++]() | |
} | |
function loop() { | |
print() | |
next() | |
} | |
loop() | |
} | |
fizzBuzz(1, 20) | |
/* | |
1 -> 1 | |
2 -> 2 | |
3 -> Fizz | |
4 -> 4 | |
5 -> Buzz | |
6 -> Fizz | |
7 -> 7 | |
8 -> 8 | |
9 -> Fizz | |
10 -> Buzz | |
11 -> 11 | |
12 -> Fizz | |
13 -> 13 | |
14 -> 14 | |
15 -> FizzBuzz | |
16 -> 16 | |
17 -> 17 | |
18 -> Fizz | |
19 -> 19 | |
20 -> Buzz | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment