Without checking the cache first, every call runs the real function.
Acceptance criteria
- 1.#out should show 1.
Without checking the cache first, every call runs the real function.
function memoize(fn) { const cache = new Map(); return function (n) { const result = fn(n); cache.set(n, result); return result; }; } let calls = 0; const double = memoize(function (n) { calls++; return n * 2; }); double(5); double(5); document.querySelector('#out').textContent = String(calls);
Output ready when you are
Press Run to render your code, or Submit to validate your solution.