about summary refs log tree commit diff stats
path: root/rnd
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2022-12-16 12:24:23 -0500
committerelioat <elioat@tilde.institute>2022-12-16 12:24:23 -0500
commitd5c10bcdb5681ab1fc23998439a0c44b6955f673 (patch)
treee35d9778b3544397e4cab67fff671400606ed35d /rnd
parenteaf9cbdb1d18e6fcd78c7673d4947fb96f409839 (diff)
downloaddecember-2022-d5c10bcdb5681ab1fc23998439a0c44b6955f673.tar.gz
...
Diffstat (limited to 'rnd')
-rw-r--r--rnd/js/memoize.js9
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