leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2623.js (304B)


      1 /**
      2  * @param {Function} fn
      3  */
      4 
      5 function memoize(fn) {
      6   const cache = {};
      7   return function(...args) {
      8     const key = JSON.stringify(args);
      9     if (key in cache) {
     10       return cache[key];
     11     }
     12     const functionOutput = fn(...args);
     13     cache[key] = functionOutput;
     14     return functionOutput;
     15   }
     16 }