Skip to content

Instantly share code, notes, and snippets.

@toriaezunama
Last active April 16, 2018 18:25
Show Gist options
  • Save toriaezunama/db5abd033461c32dee486f8716006303 to your computer and use it in GitHub Desktop.
Save toriaezunama/db5abd033461c32dee486f8716006303 to your computer and use it in GitHub Desktop.
Extension of javascript Set adding union, intersection & difference member functions
class SSet extends Set {
union(a) {
return new SSet([...this, ...a]);
}
intersection(a) {
return new SSet([...this].filter(x => a.has(x)));
}
difference(a) {
return new SSet([...this].filter(x => !a.has(x)));
}
log() {
console.log(Array.from(this));
}
toArray() {
return Array.from(this);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment