7 kyu

Fast Fibonacci

Description:

Fast Fibonacci

The generic implementation of the fibonacci algorithm is usually something like the following

function fib(num) {
  if (num < 2) return num;
  return fib(num - 1) + fib(num - 2);
}

Now thats all and well and good but that function isn't too efficient. If I wanted to get the 1000th number in the series, I'd have to wait... days? maybe years?

Your task

Write a more efficient fibonacci function that can calculate the 1000th+ number series without breaking a sweat. Read up on tail call optimization for some help.

Starting values

fib(0) = 0;
fib(1) = 1;
Functional Programming
Algorithms

More By Author:

Check out these other kata created by nrgarg

Stats:

CreatedJun 5, 2015
PublishedJun 5, 2015
Warriors Trained1821
Total Skips112
Total Code Submissions2203
Total Times Completed875
JavaScript Completions875
Total Stars35
% of votes with a positive feedback rating87% of 176
Total "Very Satisfied" Votes140
Total "Somewhat Satisfied" Votes25
Total "Not Satisfied" Votes11
Ad
Contributors
  • nrgarg Avatar
  • joh_pot Avatar
Ad