Created
September 26, 2022 12:50
-
-
Save arihantdaga/5a242af9d05f7091ab7738cfa1e0474f to your computer and use it in GitHub Desktop.
Intersection of sets
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
function getIntersection(setA, setB) { | |
const intersection = new Set( | |
[...setA].filter(element => setB.has(element)) | |
); | |
return intersection; | |
} | |
// const set1 = new Set(['a', 'b', 'c']); | |
// const set2 = new Set(['a', 'b', 'd', 'e']); | |
// console.log(getIntersection(set1, set2)); // 👉️ {'a', 'b'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment