Skip to content

Instantly share code, notes, and snippets.

@octagonal octagonal/fib.js
Last active Sep 6, 2018

Embed
What would you like to do?
Fibonacci sequence codegolf
// This is the shortest fib function using generators afaik
// Will exceed the call stack eventually
function fib(n) {
const f = function* run(a = 0, b = 1) {
yield a;
yield* run(b, a + b);
}();
return Array(n).fill().map(()=>f.next().value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.