Created
October 4, 2018 15:39
-
-
Save hg-pyun/6ff9fe54f85e484d319e99249a9fbb1b to your computer and use it in GitHub Desktop.
iterator.08.js
This file contains 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, curr] = [1, 1]; | |
while (true) { | |
[prev, curr] = [curr, prev + curr]; | |
yield curr; | |
} | |
} | |
for (let n of fibonacci()) { | |
console.log(n); | |
if (n >= 1000) { | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment