Skip to content

Instantly share code, notes, and snippets.

@nhunzaker
Created June 4, 2012 13:43
Show Gist options
  • Save nhunzaker/2868463 to your computer and use it in GitHub Desktop.
Save nhunzaker/2868463 to your computer and use it in GitHub Desktop.
Ridiculous Fibonacci Calculator
function fib (step) {
fib.times = fib.times || 0;
fib.times += step || 1;
clearTimeout(fib.calculate);
fib.calculate = setTimeout(function() {
var first = 0,
second = 1,
total = 0;
for(var i = 2; i <= fib.times; i++) {
total = first + second;
first = second;
second = total;
}
console.log("Fibonacci of %s : %s", fib.times, total);
fib.times = 0;
}, 0);
return fib;
}
fib(2)(4)(6)(8); //=> Fibonacci of 20 : 6765
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment