var fib = (function() { var cache = [ 1, 1 ]; var f = function(num) { if (num <= 0) thrownewError("Num not less than 1."); if (num >= cache.length) { for (var i = cache.length; i <= num; i++) { cache[i] = cache[i - 2] + cache[i - 1]; } } return cache[num - 1]; }; return f; })();