Created
September 28, 2016 19:28
-
-
Save juanmaguitar/8848f2970b671b8244434c2d5ccb3d3a to your computer and use it in GitHub Desktop.
fibonacci - generators
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() { | |
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