Skip to content

Instantly share code, notes, and snippets.

@Constellation
Created January 17, 2013 12:21
Show Gist options
  • Save Constellation/4555592 to your computer and use it in GitHub Desktop.
Save Constellation/4555592 to your computer and use it in GitHub Desktop.
function fibonacci() {
let [prev, curr] = [0, 1];
for (;;) {
[prev, curr] = [curr, prev + curr];
yield curr;
}
}
function take(n, gen) {
for (let i = 0; i < n; ++i) {
yield gen.next();
}
}
let numbers = [n for (n of take(10, fibonacci()))];
print(numbers);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment