Skip to content

Instantly share code, notes, and snippets.

@juanmaguitar
Created September 28, 2016 19:28
Show Gist options
  • Save juanmaguitar/8848f2970b671b8244434c2d5ccb3d3a to your computer and use it in GitHub Desktop.
Save juanmaguitar/8848f2970b671b8244434c2d5ccb3d3a to your computer and use it in GitHub Desktop.
fibonacci - generators
function *fibonacci() {
let [prev, current] = [0, 1];
while(true) {
[prev, current] = [current, prev + current];
yield current;
}
}
let seq = fibonacci();
let arrayFib = [];
for (num of seq) {
if (num > 1000) break;
arrayFib.push(num)
}
console.log (arrayFib.join(" - "))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment