Created
November 15, 2017 17:05
-
-
Save cyan33/deef99ff94fd78cff230e77fc0cfd975 to your computer and use it in GitHub Desktop.
generator based fibonacci
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 *gen() { | |
var f1 = 0; | |
var f2 = 1; | |
yield f1; | |
yield f2; | |
while (true) { | |
yield f1 + f2; | |
[f1, f2] = [f2, f1 + f2]; | |
} | |
} | |
function fibonacci() { | |
var g = gen(); | |
var i = 0; | |
while (i++ < 100) { | |
console.log(g.next().value) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment