You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
12 lines
341 B
12 lines
341 B
/**
|
|
* @description: 数组交集
|
|
* @param {Array} arr1
|
|
* @param {Array} arr2
|
|
* @return {Array}
|
|
* @example: arrayIntersect([1,2,3],[2,3,4]) //[2, 3]
|
|
*/
|
|
export default function arrayIntersect(arr1 = [], arr2 = []) {
|
|
const set1 = new Set(arr1);
|
|
const set2 = new Set(arr2);
|
|
return [...new Set([...set1].filter(x => set2.has(x)))];
|
|
}
|
|
|