What is the easiest code for array intersection in JavaScript?

JavascriptObject Oriented ProgrammingFront End Technology

For array intersection, you can try to run the following code in JavaScript −

Example

<html>
   <body>
      <script>
         let intersection = function(x, y) {
            x = new Set(x), y = new Set(y);
            return [...x].filter(k => y.has(k));
         };

         document.write(intersection([5,7,4,8], [3,9,8,4,3]));
      </script>
   </body>
</html>
raja
Published on 27-Feb-2018 13:15:21
Advertisements