Problem, as an interviewer would state it:
"Implement memoize(fn, options) — cache the result of a call so repeated calls with the same arguments skip real recomputation. Support a custom resolver function for computing the cache key, and a maxSize that evicts the oldest entry once exceeded."
Examples:
const memoSquare = memoize(expensiveSquare);
memoSquare(5); // real computation
memoSquare(5); // cached, no real computation
Clarifying questions expected:
- If no resolver is given, how should the default cache key be computed for multiple arguments?
- On maxSize eviction, is it always the LEAST RECENTLY USED entry that goes, or strictly the oldest by insertion?
- Should accessing a cached entry refresh its recency for eviction purposes?
Code / implementation expected: Yes — real, direct proof of plain caching, a custom resolver ignoring an argument, and maxSize eviction genuinely forcing a real recomputation.