Skip to content

Instantly share code, notes, and snippets.

@bigsan
Last active February 13, 2017 02:11
Show Gist options
  • Save bigsan/0c219bf2c786a25a53738b03a529b948 to your computer and use it in GitHub Desktop.
Save bigsan/0c219bf2c786a25a53738b03a529b948 to your computer and use it in GitHub Desktop.
fibonacci using es6 generator
const fibonacci = {
[Symbol.iterator]: function* () {
yield 0;
yield 1;
let [pre, cur] = [0, 1];
while (true) {
[pre, cur] = [cur, pre + cur]
yield cur;
}
}
}
for (const n of fibonacci) {
if (n > 1000)
break;
console.log(n);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment