Skip to content

Instantly share code, notes, and snippets.

@matsu-chara
Created April 15, 2015 03:52
Show Gist options
  • Save matsu-chara/ff5e82747a246c3a485f to your computer and use it in GitHub Desktop.
Save matsu-chara/ff5e82747a246c3a485f to your computer and use it in GitHub Desktop.
generator fizzbuzz in JS
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