Skip to content

Instantly share code, notes, and snippets.

@libertylocked
Last active July 26, 2017 01:36
Show Gist options
  • Save libertylocked/9ae94fe2d1397ec0d552f09d1c90fca5 to your computer and use it in GitHub Desktop.
Save libertylocked/9ae94fe2d1397ec0d552f09d1c90fca5 to your computer and use it in GitHub Desktop.
'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