Last active
July 9, 2016 11:12
-
-
Save heroqu/e574c878190d1352216948b425e726cf to your computer and use it in GitHub Desktop.
Yet another ES6 Fibonacci generator
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
| '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