AFFILIATE LINKS
Great resource I use to learn algorithms.
40% off Tech Interview Pro: http://techinterviewpro.com/terriblewhiteboard
20% off CoderPro: http://coderpro.com/terriblewhiteboard
Here is the full implementation.
/**
* @param {number[]} nums1
* @param {number[]} nums2
* @return {number[]}
*/
let intersection = function(nums1, nums2) {
let firstSet = new Set();
for (let num of nums1) {
firstSet.add(num);
}
let intersectionSet = new Set();
for (let num of nums2) {
if (firstSet.has(num)) {
intersectionSet.add(num);
}
}
return Array.from(intersectionSet);
};