simponic.xyz/euler-golf/js/json-ds.js

20 lines
442 B
JavaScript
Raw Normal View History

2023-02-23 20:18:31 -05:00
class JSONSet {
items = new Set();
2023-02-24 14:15:06 -05:00
2023-02-23 20:18:31 -05:00
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))
);
}
2023-02-24 14:15:06 -05:00
2023-02-23 20:18:31 -05:00
apply_set_function(f_name, x) {
return this.items[f_name](JSON.stringify(x));
}
}