const factorial = (n) => (n > 1 ? n * factorial(n - 1) : 1); const memoize = (fn) => { const cache = {}; return (...args) => { const key = JSON.stringify(args); return key in cache ? cache[key] : (cache[key] = fn.apply(null, args)); }; }; const memoizedFactorial = memoize(factorial); console.log(memoizedFactorial(9, { name: 'Todd Motto' })); console.log(memoizedFactorial(6)); console.log(memoizedFactorial(9, { name: 'Todd Motto' }));