Skip to content

Instantly share code, notes, and snippets.

@octagonal
Last active September 6, 2018 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save octagonal/e9111efc59c07d30ff275c609f4f218b to your computer and use it in GitHub Desktop.
Save octagonal/e9111efc59c07d30ff275c609f4f218b to your computer and use it in GitHub Desktop.
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