Back to Problem Library
Higher-Order Functions

Implement Memoize

easyJS / TS

Problem Statement

Implement a `memoize` function that takes a function `fn` and returns a memoized version that caches results based on arguments stringification.

Examples

Example:
let callCount = 0;
const memoizedFn = memoize((a, b) => { callCount++; return a + b; });
memoizedFn(2, 2); // 4
memoizedFn(2, 2); // 4 (cached, callCount stays 1)
Includes TypeScript & JavaScript starter code
Start Interview with this Problem