Created
July 19, 2016 22:48
-
-
Save BrandonZacharie/f1f1ccd86ab0976e936616e2914171e3 to your computer and use it in GitHub Desktop.
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
'use strict'; | |
/** | |
* Provides extensions to the built-in `Set`. | |
* @class | |
*/ | |
module.exports = class Set extends Set { | |
/** | |
* Returns a `Set` composed of the elements in the | |
* current `Set` and a given `set`. | |
* @argument {Set} | |
* @return {Set} | |
*/ | |
union(set) { | |
return new Set([...this, ...set]); | |
} | |
/** | |
* Returns a `Set` whose elements are in either the | |
* current `Set` or a given `set`. | |
* @argument {Set} | |
* @return {Set} | |
*/ | |
difference(set) { | |
return new Set([...this].filter((v) => !set.has(v))); | |
} | |
/** | |
* Returns a `Set` whose elements are in both the | |
* current `Set` and a given `set`. | |
* @argument {Set} | |
* @return {Set} | |
*/ | |
intersection(set) { | |
return new Set([...this].filter((v) => set.has(v))); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment