代码拉取完成,页面将自动刷新
<!-- <script>
// 并集
// [1,2,3] 并 [4,5,6] ==> [1,2,3,4,5,6]
// [1,2,3,3] 并 [4,5,6,6] ==> [1,2,3,4,5,6]
// [1,2,3,3] 并 [3,6,6] ==> [1,2,3,6]
let arr1 = [1,2,3,3];
let arr2 = [4,5,6,3,2,4,9];
function union(arr1,arr2){
let res = new Set([...arr1,...arr2])
return [...res]
}
let newArr = union(arr1,arr2);
console.log(newArr)
</script> -->
<!-- <script>
// 交集
// [1,2,3] 交 [3,4,5,6] ==> [3]
// [1,2,3] 交 [7,8,9] ==> []
// [1,2,3] 交 [1,2,3] ==> [1,2,3]
let arr1 = [1,2,3,3];
let arr2 = [3,4,5,5];
function intersection(arr1,arr2){
let s1 = new Set(arr1)
let s2 = new Set(arr2)
let newArr = [...s1].filter(item=>{
return s2.has(item)
})
return newArr
}
let newArr = intersection(arr1,arr2);
console.log(newArr)
</script> -->
<script>
// 差集
// [1,2,3] 差 [3,4,5] ==> [1,2]
// [3,4,5] 差 [1,2,3] ==> [4,5]
let arr1 = [1, 2, 3];
let arr2 = [3, 4, 5];
function except(arr1, arr2) {
let s1 = new Set(arr1)
let s2 = new Set(arr2)
let newArr = [...s1].filter(item => {
return !s2.has(item)
})
return newArr;
}
console.log(except(arr1, arr2)) // [1,2]
console.log(except(arr2, arr1)) // [4,5]
</script>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。