Last active
February 13, 2017 02:11
-
-
Save bigsan/0c219bf2c786a25a53738b03a529b948 to your computer and use it in GitHub Desktop.
fibonacci using es6 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
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