共计 252 个字符,预计需要花费 1 分钟才能阅读完成。
// 办法一:
const intersection = (arr,arr1) => {let obj = {} , res = [];
arr.forEach(item => {obj[item] = true;
})
arr1.forEach(item => {if(obj[item]){res.push(item)
obj[item] = false
}
})
return res
}
// 办法二:
const intersection = (arr,arr1) => [...new Set (arr.filter(item => arr1.includes(item)))]
正文完