From 445af5d0be53375355b9dad02510f6b331fd99ec Mon Sep 17 00:00:00 2001 From: Lizzy Hunt Date: Fri, 24 Feb 2023 15:02:20 -0700 Subject: Euler golf (#1) --- euler-golf/js/json-ds.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 euler-golf/js/json-ds.js (limited to 'euler-golf/js/json-ds.js') 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)); + } +} -- cgit v1.2.3-70-g09d2