Implement memoize(func) for functions that take any number of arguments. Two calls hit the same cache entry only if they pass the same number of arguments and every argument matches its counterpart.
const area = memoize((w, h) => w * h);
area(2, 3); // 6, computed
area(2, 3); // 6, cached
area(3, 2); // 6, computed (different order is a different key)
const config = { dark: true };
const render = memoize((node, opts) => /* ... */ null);
render('a', config); // computed
render('a', config); // cached (same object reference)
render('a', { dark: true }); // computed (different reference)
1 and '1' differ.NaN matches NaN.f(1), f(1, undefined) and f() are three different entries.f('a,b') and f('a', 'b') must not share an entry.undefined. If func throws, nothing is cached.this is forwarded to func. (It is not part of the key.)clear() method that empties the cache.resolver that serialises arguments be acceptable after all?Spotted a mistake or a rights concern? Report an issue