Created
December 23, 2015 21:54
-
-
Save tlkahn/4247dcf60008237902c9 to your computer and use it in GitHub Desktop.
es6 recursive generator
This file contains hidden or 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
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