Skip to content

Instantly share code, notes, and snippets.

@hg-pyun
Created October 4, 2018 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hg-pyun/6ff9fe54f85e484d319e99249a9fbb1b to your computer and use it in GitHub Desktop.
Save hg-pyun/6ff9fe54f85e484d319e99249a9fbb1b to your computer and use it in GitHub Desktop.
iterator.08.js
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