Skip to content

Instantly share code, notes, and snippets.

@heroqu
Last active July 9, 2016 11:12
Show Gist options
  • Save heroqu/e574c878190d1352216948b425e726cf to your computer and use it in GitHub Desktop.
Save heroqu/e574c878190d1352216948b425e726cf to your computer and use it in GitHub Desktop.
Yet another ES6 Fibonacci generator
'use strict'
function* fibo() {
let [a,b] = [0,1];
while (true) {
yield b;
[a, b] = [b, a + b];
}
}
// Let's print first 1000 Fibonacci numbers:
const N = 1000;
let fi = fibo();
[...Array(N).keys()].forEach((v,i) => console.log(i+1, fi.next().value));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment