Skip to content

Instantly share code, notes, and snippets.

@zsteva
Last active June 9, 2024 18:02
Show Gist options
  • Save zsteva/83eea80008ef3aac4803a0c9afb87028 to your computer and use it in GitHub Desktop.
Save zsteva/83eea80008ef3aac4803a0c9afb87028 to your computer and use it in GitHub Desktop.
const symbol_set = Symbol("set");
export class ArraySet {
constructor() {
this[symbol_set] = new Set();
}
get size() {
return this[symbol_set].size;
}
add(...elements) {
this[symbol_set].add(elements.join('-'));
}
clear() {
this[symbol_set].clear();
}
has(...elements) {
return this[symbol_set].has(elements.join('-'));
}
*[Symbol.iterator]() {
for (let item of this[symbol_set][Symbol.iterator]()) {
yield item.split('-');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment