Set Methods for JavaScript
https://github.com/tc39/proposal-set-methods
TypeScriptのSetに対する新しいmethodの追加の提案
Set.prototype.intersection(other)
2つのSetの共通要素
code:js
let set1 = new Set("apples", "bananas");
let set2 = new Set("apples", "oranges");
console.log(set1.intersection(set2)); // Set(1) {'apples'}
Set.prototype.union(other)
2つのSetの和
code:js
let set1 = new Set("apples", "bananas");
let set2 = new Set("apples", "oranges");
console.log(set1.union(set2)); // Set(3) {'apples', 'bananas', 'oranges'}
Set.prototype.difference(other)
差
Set.prototype.symmetricDifference(other)
2つのSetの共通していない部分
code:js
let set1 = new Set("apples", "bananas");
let set2 = new Set("apples", "oranges");
console.log(set1.symmetricDifference(set2)); // Set(2) {'bananas', 'oranges'}
Set.prototype.isSubsetOf(other)
subsetかどうか
code:js
let set1 = new Set("apples", "bananas");
let set2 = new Set("apples", "bananas", "oranges");
console.log(set1.isSubsetOf(set2)); // true
Set.prototype.isSupersetOf(other)
supersetかどうか
code:ts
let set1 = new Set("apples", "bananas", "oranges");
let set2 = new Set("apples", "bananas");
console.log(set1.isSupersetOf(set2)); // true
Set.prototype.isDisjointFrom(other)
交差していないかどうか
交差していないとtrue
code:js
let set1 = new Set("apples", "bananas");
let set2 = new Set("oranges", "pears");
console.log(set1.isDisjointFrom(set2)); // true
#ECMAScript_Proposal