diff options
| author | Elizabeth Alexander Hunt <me@liz.coffee> | 2026-07-05 12:42:44 -0700 |
|---|---|---|
| committer | Elizabeth Alexander Hunt <me@liz.coffee> | 2026-07-05 12:42:44 -0700 |
| commit | 94b912b649150b9863a62096ba4740b2cc8ad21a (patch) | |
| tree | 1882236fc980fa5946d3089a2f2e4670f3a70580 /html/toys/euler-golf/js/json-ds.js | |
| parent | ab0ddcaeb1fc37351d14b89100e07d3a343ba9e1 (diff) | |
| download | lizdotcoffee-94b912b649150b9863a62096ba4740b2cc8ad21a.tar.gz lizdotcoffee-94b912b649150b9863a62096ba4740b2cc8ad21a.zip | |
Factor
Diffstat (limited to 'html/toys/euler-golf/js/json-ds.js')
| -rw-r--r-- | html/toys/euler-golf/js/json-ds.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/html/toys/euler-golf/js/json-ds.js b/html/toys/euler-golf/js/json-ds.js new file mode 100644 index 0000000..dc7e88e --- /dev/null +++ b/html/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)); + } +} |
