Skip to content

Instantly share code, notes, and snippets.

@CrossEye
Created May 19, 2013 04:04
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 CrossEye/5606638 to your computer and use it in GitHub Desktop.
Save CrossEye/5606638 to your computer and use it in GitHub Desktop.
Simple, tail-recursive version of Fibonacci. Should run in nearly O(n).
var fibonacci = (function() {
var fib = function(curr, next, n) {
return (n === 0) ? curr : fib(next, curr + next, n - 1);
};
return function(n) {
return fib(0, 1, n);
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment