Skip to content

Instantly share code, notes, and snippets.

@jslnriot
Created December 12, 2022 02:06
Show Gist options
  • Save jslnriot/5cd1b90c2be473c522059ca5bb3b0c91 to your computer and use it in GitHub Desktop.
Save jslnriot/5cd1b90c2be473c522059ca5bb3b0c91 to your computer and use it in GitHub Desktop.
// create some sets
let setA = new Set([1, 2, 3, 4]);
let setB = new Set([3, 4, 5, 6]);
let setC = new Set([5, 6, 7, 8]);
// create a new set with the union of setA, setB, and setC
let unionSet = new Set([...setA, ...setB, ...setC]);
console.log(unionSet); // Set {1, 2, 3, 4, 5, 6, 7, 8}
// create a new set with the intersection of setA, setB, and setC
let intersectionSet = new Set([...setA].filter(x => setB.has(x) && setC.has(x)));
console.log(intersectionSet); // Set {5, 6}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment