javascript intermediate ينتهي في 2026-11-17

Memoize with a cache limit

Write memoize(fn, limit) that returns a function which remembers results by its arguments.

  • Calling it again with the same arguments returns the cached result without calling fn.
  • Arguments are compared by value: use JSON.stringify(args) as the cache key.
  • Keep at most limit results; when full, forget the oldest entry.
  • The returned function has a .clear() method that empties the cache.

Acceptance criteria

  • The tests at the bottom print All tests passed.

Hint: a Map remembers insertion order, and map.keys().next().value is the oldest key.

حلّه 0 شخصًا حتى الآن.

javascript
المحررCtrl + Enter

            
        

عندما تطبع الاختبارات "All tests passed" يُعلَّم التحدي كمحلول في هذا المتصفح.

إرسال حلك للمراجعة