1// Union (a ∪ b)
2let a = new Set([1,2,3]);
3let b = new Set([4,3,2]);
4let union = new Set([...a, ...b]);
5 // {1,2,3,4}
6
7// Intersection (a ∩ b)
8let a = new Set([1,2,3]);
9let b = new Set([4,3,2]);
10let intersection = new Set(
11 [...a].filter(x => b.has(x)));
12 // {2,3}
13
14// Difference (a \ b)
15let a = new Set([1,2,3]);
16let b = new Set([4,3,2]);
17let difference = new Set(
18 [...a].filter(x => !b.has(x)));
19 // {1}