Last active
August 18, 2019 07:15
-
-
Save Tomotoes/62f163eb32bfb091831a0b8a958c26c8 to your computer and use it in GitHub Desktop.
Es6 realizes Fibonacci sequence
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] = [0, 1]; | |
while (true) { | |
[prev, curr] = [curr, prev + curr]; | |
yield curr; | |
} | |
} | |
for (let 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