Created
January 21, 2015 04:14
-
-
Save kumavis/19fb4f6bd25b19ba9083 to your computer and use it in GitHub Desktop.
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
function* addGenerator() { | |
var i = 0; | |
while (true) { | |
i += yield i; | |
} | |
} | |
var adder = addGenerator(); | |
adder.next().value; // 0 | |
adder.next(5).value; // 5 | |
adder.next(5).value; // 10 | |
adder.next(5).value; // 15 | |
adder.next(50).value; // 65 |
Author
kumavis
commented
Jan 21, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment