I\'ve read
http://www.sitepoint.com/implementing-memoization-in-javascript/
In all of the previous examples, the functi
The memoize
call does not alter the fib
function, but returns its new, memoized counterpart. In your code, you're calling that one only once, and the original fib
function the next time. You need to create one memoized "wrapper", and call that multiple times:
var mFib = memoize(fib);
log(mFib(43));
log(mFib(43));
You could also overwrite the original fib = memoize(fib);
, which would have the additional benefit that the recursive calls (which are the interesting ones) will be memoized as well.