Created
June 4, 2012 13:43
-
-
Save nhunzaker/2868463 to your computer and use it in GitHub Desktop.
Ridiculous Fibonacci Calculator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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