MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1vda9j/deleted_by_user/cerb6kk/?context=3
r/ProgrammerHumor • u/[deleted] • Jan 16 '14
[removed]
446 comments sorted by
View all comments
Show parent comment
3
This inspired me to make a horribly contrived version in JS:
function isFizz(i) { return i%divisors.FIZZ === 0; } function isBuzz(i) { return i%divisors.BUZZ === 0; } function isFizzBuzz(i) { return isFizz(i) && isBuzz(i); } var divisors = { FIZZ: 3, BUZZ: 5 }; var functionsAndResults = [ { function: isFizzBuzz, msg: "FizzBuzz" }, { function: isFizz, msg: "Fizz" }, { function: isBuzz, msg: "Buzz" }, ]; for(var i=1; i<=100; i++) { var calledFunction = false; for(var func=0; func<functionsAndResults.length; func++) { if(functionsAndResults[func].function(i)) { console.log(functionsAndResults[func].msg); calledFunction = true; break; } } if(!calledFunction) console.log(i); }
Had I been doing more CoffeeScript at the time, this could be a lot more elegant. C'est la vie.
(See also: Enterprise Fizz Buzz)
View all comments
Show parent comment
3
u/seiyria Jan 16 '14
This inspired me to make a horribly contrived version in JS:
Had I been doing more CoffeeScript at the time, this could be a lot more elegant. C'est la vie.
(See also: Enterprise Fizz Buzz)