Skip to content

Instantly share code, notes, and snippets.

@zekrom-vale
Created July 22, 2019 02:47
Show Gist options
  • Save zekrom-vale/7df17ccb8b8d21448aa27e00e30f0763 to your computer and use it in GitHub Desktop.
Save zekrom-vale/7df17ccb8b8d21448aa27e00e30f0763 to your computer and use it in GitHub Desktop.
Fibonacci sequence using generators in js
function* F(){
yield 1;
yield 1;
var N=[1,1];
while(true){
let sum=N[0]+N[1];
N=[N[1], sum];
yield sum;
}
}
var f=F();
for(let i=0; i<30; i++)console.log(f.next());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment