var memoizer = function (memo, func) { var recur = function (n) { var result = memo[n]; if (typeof result !== ‘number‘) { result = func (recur, n); } return result; }; return recur; };
var fibonacci = memoizer([0, 1], function (recur, n) { return recur (n - 1) + recur(n - 2); });
时间: 2024-10-13 11:21:18