How do I get to display the elements that make up the intersection of two sets without it displaying [object set]
?
const setA = new Set([1, 2, 3, 4]);
const setB = new Set([3, 4, 5, 6]);
function intersection(setA, setB) {
const result = new Set();
for (const elem of setA) {
if (setB.has(elem)) {
result.add(elem);
}
}
return result;
}
console.log(intersection(setA, setB));