Created
May 28, 2018 20:06
-
-
Save roden0/cc9cdc5c45a2116e905242962f30d206 to your computer and use it in GitHub Desktop.
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
| function* fibonacci() { // una función generador | |
| let [prev, curr] = [0, 1]; | |
| while (true) { | |
| [prev, curr] = [curr, prev + curr]; | |
| yield curr; | |
| } | |
| } | |
| for (let n of fibonacci()) { | |
| console.log(n); | |
| // interrumpir la secuencia en 1000 | |
| if (n >= 100) { | |
| break; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment