frontend-challenges icon indicating copy to clipboard operation
frontend-challenges copied to clipboard

55 - memo - javascript

Open jsartisan opened this issue 1 year ago • 0 comments

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];
  }
}

jsartisan avatar Apr 27 '24 06:04 jsartisan