79618674

Date: 2025-05-12 21:50:05
Score: 0.5
Natty:
Report link

Provided you don't need to worry about keeping track of calculated nulls, you can make use of null-ish coalescing assignment (??=).

function memoize(result) {
  const cache = {};

  return function() {
    cache[result] ??= calculate(result);
    return cache[result];
  };
}
Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Andy Doyle