diff options
Diffstat (limited to 'maize-maze/js/json-ds.js')
-rw-r--r-- | maize-maze/js/json-ds.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/maize-maze/js/json-ds.js b/maize-maze/js/json-ds.js new file mode 100644 index 0000000..feb0622 --- /dev/null +++ b/maize-maze/js/json-ds.js @@ -0,0 +1,30 @@ +// If I were to rewrite this, I would use IEFE's - Dean was right about OO in JS +class JSONSet { + items = new Set(); + constructor(initial){ + if (initial) { + this.apply_set_function('add', initial); + } + } + apply_set_function(f_name, x) { + return this.items[f_name](JSON.stringify(x)); + } +} + +class JSONHash { + items = {}; + constructor(initial_key, initial_value){ + if (initial_key && initial_value) { + this.items[JSON.stringify(initial)] = initial_value; + } + } + set_value(key, value) { + this.items[JSON.stringify(key)] = value; + } + get_value(key) { + return this.items[JSON.stringify(key)]; + } + delete_value(key) { + delete this.items[JSON.stringify(key)]; + } +}
\ No newline at end of file |