Skip to content

Instantly share code, notes, and snippets.

@arihantdaga
Created September 26, 2022 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arihantdaga/5a242af9d05f7091ab7738cfa1e0474f to your computer and use it in GitHub Desktop.
Save arihantdaga/5a242af9d05f7091ab7738cfa1e0474f to your computer and use it in GitHub Desktop.
Intersection of sets
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