Created
April 15, 2015 03:52
-
-
Save matsu-chara/ff5e82747a246c3a485f to your computer and use it in GitHub Desktop.
generator fizzbuzz in JS
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
require("babel/polyfill"); | |
function* fizbuzgen() { | |
for(var i = 0;; ++i) { | |
if(i % 15 === 0) { yield "fizzbuzz"; } | |
else if(i % 5 === 0) { yield "buzz"; } | |
else if(i % 3 === 0) { yield "fizz"; } | |
else { yield "" + i; } | |
} | |
} | |
function fizzbuzz() { | |
var gen = fizbuzgen(); | |
for(var i = 0; i <= 100; ++i) { | |
console.log(gen.next().value); | |
} | |
} | |
fizzbuzz(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment