Created
January 10, 2016 17:45
-
-
Save alexnm/58e73bbc48fbd4321f13 to your computer and use it in GitHub Desktop.
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
function* fibonacci( ){ | |
let n1 = 0; | |
let n2 = 1; | |
while ( true ) { | |
const current = n1; | |
n1 = n2; | |
n2 = current + n1; | |
yield current; | |
} | |
} | |
let iterator = fibonacci( ); | |
iterator.next( ); // 0 | |
iterator.next( ); // 1 | |
iterator.next( ); // 1 | |
iterator.next( ); // 2 | |
iterator.next( ); // 3 | |
iterator.next( ); // 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment