Skip to solution
mediumFrontend

Implement memoize() with custom resolver and cache limit

607 views
01

Understand the problem

Create memoize(func, resolver?, maxSize?) that caches results. Resolver derives cache key. Evict oldest when maxSize exceeded.

memoizecacheclosure
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

Approach: Map cache keyed by resolver or JSON.stringify. On hit return cached; on miss compute, set, and evict if over maxSize. Expose cache Map.

function memoize(func, resolver, maxSize = Infinity) {
  const cache = new Map();
  function memoized(...args) {
    const key = resolver ? resolver(...a

Solution ready — 2 min read

Classified // press E to declassify

04

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 134 of 190 decoded in the JavaScript Coding track. One more won't hurt.

Back to track