Skip to content

Instantly share code, notes, and snippets.

@cyan33
Created November 15, 2017 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyan33/deef99ff94fd78cff230e77fc0cfd975 to your computer and use it in GitHub Desktop.
Save cyan33/deef99ff94fd78cff230e77fc0cfd975 to your computer and use it in GitHub Desktop.
generator based fibonacci
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