数组并交差集 发表于 2019-04-08 现有两数组a = [1, 2, 3],b = [2, 4, 5],求a,b数组的并集,交集和差集 1234567891011// 并集let union = a.concat(b.filter(v => !a.includes(v)));// [1,2,3,4,5]// 交集let intersection = a.filter(v => b.includes(v));// [2]// 差集let difference = a.concat(b).filter(v => !a.includes(v) || !b.includes(v));// [1,3,4,5] 12345// 交集[[1, 2, 3], [1, 3, 5], [6, 8, 1]].reduce((x, y) => { return x.filter(el => y.includes(el));});// [1]