Last active
February 11, 2020 00:05
-
-
Save vldvel/9537f2a467a234e8b243fb28d6e22fa8 to your computer and use it in GitHub Desktop.
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
| function * fibonacci(seed1, seed2) { | |
| while (true) { | |
| yield (() => { | |
| seed2 = seed2 + seed1; | |
| seed1 = seed2 - seed1; | |
| return seed2; | |
| })(); | |
| } | |
| } | |
| const fib = fibonacci(0, 1); | |
| fib.next(); // {value: 1, done: false} | |
| fib.next(); // {value: 2, done: false} | |
| fib.next(); // {value: 3, done: false} | |
| fib.next(); // {value: 5, done: false} | |
| fib.next(); // {value: 8, done: false} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment