两个数组 var A = [1, 5, 6]; var B = [2, 6, 7]
,实现一个方法,找出仅存在于A
或者仅存在于B
中的所有数字
const filterArr = (arr1, arr2) => {
const arr = [...arr1,...arr2]
const newArr = arr.filter((t) => {
return !(arr1.includes(t) && arr2.includes(t))
})
return newArr
}
const filterArr2 = (arr1, arr2] => {
return arr1.concat(arr2).filter((t,i, arr) => {
return arr.indexOf(t) === arr.lastIndexOf(t)
})
}
const arr1 = A.filter((t)=> !B.includes(t))
const arr2 = B.filter((x) => !A.includes(x))
const newArr = arr1.concat(arr2)
本人每篇文章都是一字一句码出来,希望对大家有所帮助,多提提意见。顺手来个三连击,点赞收藏关注✨,一起加油☕