swati-jagtap / javascript-practice

0 stars 0 forks source link

10.2.1 to 10.2.3 #132

Open swati-jagtap opened 3 years ago

swati-jagtap commented 3 years ago
//Set And Map
const a = [4 , 5, 8, 9]
const b = [3, 4, 5, 7]
const countries = ['Finland', 'Sweden', 'Norway']

//10.2.1--Find a union b
const c=[...a,...b];
let C=new Set(c);
console.log("a union b :",C);

//10.2.2--Find a intersection b
const B=new Set(b);
//console.log(B)
let aUnionb=new Set();
aUnionb=a.filter((value)=>B.has(value));
let aIntersectionb=new Set(aUnionb);
console.log("a intersection b:",aIntersectionb);

//10.2.3--Find a with b
const aWithb=a.filter((value)=>!B.has(value))
const AWithB=new Set(aWithb)
console.log("a with b",AWithB)

image