JavaScript 中陣列交集的最簡單程式碼是什麼?


對於陣列交集,可以在 JavaScript 中嘗試執行以下程式碼 −

示例

<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>

更新於: 23-Jun-2020

96 瀏覽

開啟您的 職業

完成課程獲得認證

開始
廣告
© . All rights reserved.