commit e08bc1709519917d51e1cec76b971f66fa164d4e parent f443d7a1613072b75d5afb6f905f57df564fce02 Author: Dimitrije Dobrota <mail@dimitrijedobrota.com> Date: Sat, 13 May 2023 18:52:31 +0200 JavaScript Challenge: Day 9 Diffstat:
A | Problems/2623.js | | | 16 | ++++++++++++++++ |
M | README.md | | | 3 | ++- |
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/Problems/2623.js b/Problems/2623.js @@ -0,0 +1,16 @@ +/** + * @param {Function} fn + */ + +function memoize(fn) { + const cache = {}; + return function(...args) { + const key = JSON.stringify(args); + if (key in cache) { + return cache[key]; + } + const functionOutput = fn(...args); + cache[key] = functionOutput; + return functionOutput; + } +} diff --git a/README.md b/README.md @@ -545,4 +545,5 @@ for solving problems. | 2635 | Easy | [Apply Transform Over Each Element in Array](Problems/2635.js) | | 2665 | Easy | [Counter II](Problems/2665.js) | | 2666 | Easy | [Allow One Function Call](Problems/2666.js) | -| 2667 | Easy | [Create Hello World Function](Problems/2667.js) | +| 2667 | Easy | [Create Hello World Function](Problems/2667.js) | +| 2623 | Medium | [Memoize](Problems/2623.js) |