Created
July 22, 2019 02:47
-
-
Save zekrom-vale/7df17ccb8b8d21448aa27e00e30f0763 to your computer and use it in GitHub Desktop.
Fibonacci sequence using generators in js
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* 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