diff options
author | elioat <elioat@tilde.institute> | 2022-12-16 12:24:23 -0500 |
---|---|---|
committer | elioat <elioat@tilde.institute> | 2022-12-16 12:24:23 -0500 |
commit | d5c10bcdb5681ab1fc23998439a0c44b6955f673 (patch) | |
tree | e35d9778b3544397e4cab67fff671400606ed35d /rnd | |
parent | eaf9cbdb1d18e6fcd78c7673d4947fb96f409839 (diff) | |
download | december-2022-d5c10bcdb5681ab1fc23998439a0c44b6955f673.tar.gz |
...
Diffstat (limited to 'rnd')
-rw-r--r-- | rnd/js/memoize.js | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/rnd/js/memoize.js b/rnd/js/memoize.js new file mode 100644 index 0000000..b70d95f --- /dev/null +++ b/rnd/js/memoize.js @@ -0,0 +1,9 @@ +const memoize = (f) => { + const cache = {}; + + return (...args) => { + const argStr = JSON.stringify(args); + cache[argStr] = cache[argStr] || f(...args); + return cache[argStr]; + }; +}; \ No newline at end of file |