A pure functional JavaScript solution


  • 0
    B
    const intersection = (nums1, nums2) =>
        nums1.map(item1 => nums2 .filter(item2 => item1 === item2))
              .reduce((result, item) => result.concat(item), [])
              .reduce((result, item) =>
                      result.indexOf(item) >= 0 ? result : result.concat([item]), []);
    
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.