1 const intersection = (a, b) => {
2 const bSet = new Set(b);
3 return a?.filter(value => bSet.has(value));
4 }
5
6 intersection([1, 2, 3], [1, 3, 5]) // [1, 3]
1 const intersection = (a, b) => {
2 const bSet = new Set(b);
3 return a?.filter(value => bSet.has(value));
4 }
5
6 intersection([1, 2, 3], [1, 3, 5]) // [1, 3]