Skip to content

Instantly share code, notes, and snippets.

@tlkahn
Created December 23, 2015 21:54
Show Gist options
  • Save tlkahn/4247dcf60008237902c9 to your computer and use it in GitHub Desktop.
Save tlkahn/4247dcf60008237902c9 to your computer and use it in GitHub Desktop.
es6 recursive generator
var gen = function *(count){
console.log("gen called: ", count);
if (count < 20)
yield count;
else
yield *gen(count/2);
}
var g = gen(100);
do {
var n = g.next();
if (!n.done) {
console.log("val: ", n.value);
}
else {
console.log("done");
}
} while (!n.done)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment