Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumJavaScriptmemoizationSingle-choice MCQ

This memoizer caches by its single object argument. What does the third call log?

function memo(fn) { const cache = new Map(); return (o) => { if (cache.has(o)) return cache.get(o); const r = fn(o); cache.set(o, r); return r; }; } let calls = 0; const double = memo((o) => { calls++; return o.v * 2; }); const a = { v: 5 }; double(a); double(a); double({ v: 5 }); console.log(calls);