Skip to content

Commit 342c568

Browse files
committed
chapter 06: [Sets]
1 parent 44c54ca commit 342c568

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

examples/chapter06/03-ES2015Set.js

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ const union = (set1, set2) => {
3535
};
3636
console.log(union(setA, setB));
3737

38+
console.log(new Set([...setA, ...setB]));
39+
3840
// --------- Intersection ----------
3941
const intersection = (set1, set2) => {
4042
const intersectionSet = new Set();
@@ -47,6 +49,8 @@ const intersection = (set1, set2) => {
4749
};
4850
console.log(intersection(setA, setB));
4951

52+
console.log(new Set([...setA].filter(x => setB.has(x))));
53+
5054
// alternative - works on FF only
5155
// console.log(new Set([x for (x of setA) if (setB.has(x))]));
5256

@@ -62,5 +66,7 @@ const difference = (set1, set2) => {
6266
};
6367
console.log(difference(setA, setB));
6468

69+
console.log(new Set([...setA].filter(x => !setB.has(x))));
70+
6571
// alternative - works on FF only
6672
// console.log(new Set([x for (x of setA) if (!setB.has(x))]));

0 commit comments

Comments
 (0)