Skip to content

Instantly share code, notes, and snippets.

@dbrockman
Created April 1, 2013 19:01
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 dbrockman/5286904 to your computer and use it in GitHub Desktop.
Save dbrockman/5286904 to your computer and use it in GitHub Desktop.
function fibonacci(n) {
return n < 2 ? n : fibonacci(n - 2) + fibonacci(n - 1);
}
function fibonacci(n) {
var prev, curr = 0, next = 1;
while (n-- > 0) {
prev = curr;
curr = next;
next = prev + curr;
}
return curr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment