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>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP