function findComplementarySet(a, b) {
// write your code here …
if (b.length > a.length) {
return []
}
else {
let bl = b.filter(x=>a.indexOf(x)>-1)
if(bl.length==0){
return []
}
let c = a.filter(x => b.indexOf(x) == -1)
return c
}
}
算出两个数组的补集,数组只包含字符串和数字 ,如果 b 是 a 的子集,返回存在于 a 不存在于 b 的元素集合,反之返回空集合
最新推荐文章于 2023-06-13 10:13:28 发布