← All Exercises
Memoization Wrapper
intermediatejavascript
Background
Memoization dramatically speeds up expensive computations like recursive Fibonacci by trading memory for speed.
Problem
Write a memoize function that wraps a pure function and caches its results based on the arguments, returning cached results for repeated calls.
Input
A pure function whose results depend only on its arguments.
Output
A memoized version of the function with an internal cache.
Sample tests
Sample 1
Input: memoizedFib(10)
Expected: 55
Your solution
Learning objective
Learn caching strategies, closure-based state, and the trade-offs of memoization.