summaryrefslogtreecommitdiff
path: root/euler-golf/js/json-ds.js
diff options
context:
space:
mode:
authorLizzy Hunt <loganhunt@simponic.xyz>2023-02-24 15:02:20 -0700
committerGitHub <noreply@github.com>2023-02-24 15:02:20 -0700
commit445af5d0be53375355b9dad02510f6b331fd99ec (patch)
treec9012d8108d3803bbeb8178163210b482188ff3c /euler-golf/js/json-ds.js
parent93c8bbeb6a0b3574cb66c25656e4da6d0b936a66 (diff)
downloadsimponic.xyz-445af5d0be53375355b9dad02510f6b331fd99ec.tar.gz
simponic.xyz-445af5d0be53375355b9dad02510f6b331fd99ec.zip
Euler golf (#1)
Diffstat (limited to 'euler-golf/js/json-ds.js')
-rw-r--r--euler-golf/js/json-ds.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/euler-golf/js/json-ds.js b/euler-golf/js/json-ds.js
new file mode 100644
index 0000000..dc7e88e
--- /dev/null
+++ b/euler-golf/js/json-ds.js
@@ -0,0 +1,19 @@
+class JSONSet {
+ items = new Set();
+
+ constructor(initial) {
+ if (Array.isArray(initial)) {
+ initial.map((x) => this.apply_set_function("add", x));
+ } else {
+ this.apply_set_function("add", initial);
+ }
+
+ ["add", "has", "remove"].forEach(
+ (f_name) => (this[f_name] = (x) => this.apply_set_function(f_name, x))
+ );
+ }
+
+ apply_set_function(f_name, x) {
+ return this.items[f_name](JSON.stringify(x));
+ }
+}