lodash.difference
创建一个具有唯一array值的数组,每个值不包含在其他给定的数组中。(注:即创建一个新数组,这个数组中的值,为排除了给定数组中的值。结果值的顺序是由第一个数组中的顺序确定。
参数:
array (Array): 要检查的数组。
[values] (...Array): 排除的值。
function difference(...agrs){
const array = agrs[0]
if(!Array.isArray(agrs[0])) return []
const excludeSet = new Set(agrs.slice(1).flat(Infinity))
let result = []
for(const value of array){
if(!excludeSet.has(value)){
result.push(value)
}
}
return result
}
console.log(difference([3, 2, 1], [1,[[[[2]]]]]))