Skip to content

Instantly share code, notes, and snippets.

@Tomotoes
Last active August 18, 2019 07:15
Show Gist options
  • Save Tomotoes/62f163eb32bfb091831a0b8a958c26c8 to your computer and use it in GitHub Desktop.
Save Tomotoes/62f163eb32bfb091831a0b8a958c26c8 to your computer and use it in GitHub Desktop.
Es6 realizes Fibonacci sequence
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