Skip to content

Instantly share code, notes, and snippets.

@AgentCoop
Created July 10, 2018 06:48
Show Gist options
  • Save AgentCoop/4d2f9cbb0f326fd69a0023e25c3acb4c to your computer and use it in GitHub Desktop.
Save AgentCoop/4d2f9cbb0f326fd69a0023e25c3acb4c to your computer and use it in GitHub Desktop.
EcmaScript 6 fibonacci numbers
function* fibonacci(n, current = 0, next = 1) {
if (n<1)
return 0;
yield current;
yield* fibonacci(n - 1, next, current + next)
}
const fib20 = fibonacci(20);
console.log([...fib20]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment