frontend-challenges
frontend-challenges copied to clipboard
55 - memo - javascript
index.js
export function memo(func) {
const cache = {};
return function(...args) {
const key = JSON.stringify(args);
if (!(key in cache)) {
cache[key] = func.apply(this, args);
}
return cache[key];
}
}