const countOccurrences = (arr) => arr.reduce((acc, curr) => {
acc[curr] = (acc[curr] || 0) 1;
return acc;
}, {});
let arr = [1, 2,3,4,2, 3, 4, 5];
console.log("参数为:", arr);
console.log("结果为:", countOccurrences(arr));
const union = (...arrays) => arrays.reduce((acc, curr) => [...new Set([...acc, ...curr])], []);
let arr = [1, 2,3,4,2, 3, 4, 5];
let arr1 = [1, 2, 3, 4, 5];
console.log("参数为:", arr,arr1);
console.log("结果为:", union(arr,arr1));
const intersection = (...arrays) => arrays.reduce((acc, curr) => acc.filter(value => curr.includes(value)));
let arr = [1, 2,3,4,2, 3, 4, 5];
let arr1 = [1, 2, 3, 4, 5];
console.log("参数为:", arr,arr1);
console.log("结果为:", intersection(arr,arr1));
const difference = (arr1, arr2) => arr1.reduce((acc, curr) => arr2.includes(curr) ? acc : [...acc, curr], []);
let arr = [1, 2,3,4,2, 3, 4, 5,9];
let arr1 = [1, 2, 3, 4, 5,7,8];
console.log("参数为:", arr,arr1);
console.log("结果为:", difference(arr,arr1));