Memoize Function
Caches results of expensive function calls to improve performance when the same input is provided repeatedly. Example: memoize(Math.sqrt).
JavaScript7/8/2025
#performance#utilities
JavaScript
function memoize(fn) { const cache = new Map(); return (arg) => { if (cache.has(arg)) return cache.get(arg); const result = fn(arg); cache.set(arg, result); return result; }; }
...
Loading comments...