Last active
July 26, 2017 01:36
-
-
Save libertylocked/9ae94fe2d1397ec0d552f09d1c90fca5 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
'use strict' | |
function* fibGen(limit) { | |
let prevVal = 0, currVal = 1; | |
let nextVal = 0; | |
while (!limit || currVal <= limit) { | |
yield currVal; | |
nextVal = currVal + prevVal; | |
prevVal = currVal; | |
currVal = nextVal; | |
} | |
} | |
for (let v of fibGen(100)) { | |
console.log(v); | |
} | |
console.log(Array.from(fibGen(100))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment