Last active
April 16, 2018 18:25
-
-
Save toriaezunama/db5abd033461c32dee486f8716006303 to your computer and use it in GitHub Desktop.
Extension of javascript Set adding union, intersection & difference member functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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