diff options
| author | Elizabeth Hunt <me@liz.coffee> | 2026-01-07 19:29:30 -0800 |
|---|---|---|
| committer | Elizabeth Hunt <me@liz.coffee> | 2026-01-07 19:29:30 -0800 |
| commit | 91b7598b22f89319f64054daf42c950de3eb6451 (patch) | |
| tree | b337ad01c75e7ee88f287eda05522e72dd9a8dd5 /src/toys/euler-golf/js/json-ds.js | |
| parent | 49012297ea792a69501b74d8d83bd4be44d177da (diff) | |
| download | lizdotcoffee-91b7598b22f89319f64054daf42c950de3eb6451.tar.gz lizdotcoffee-91b7598b22f89319f64054daf42c950de3eb6451.zip | |
Adding some of my favorite toys
Diffstat (limited to 'src/toys/euler-golf/js/json-ds.js')
| -rw-r--r-- | src/toys/euler-golf/js/json-ds.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/toys/euler-golf/js/json-ds.js b/src/toys/euler-golf/js/json-ds.js new file mode 100644 index 0000000..dc7e88e --- /dev/null +++ b/src/toys/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)); + } +} |
