function baseXor(arrays, iteratee, comparator) {
const length = arrays.length
if (length < 2) {
return length ? baseUniq(arrays[0]) : []
}
let index = -1
const result = new Array(length)
while (++index < length) {
const array = arrays[index]
let othIndex = -1
while (++othIndex < length) {
if (othIndex != index) {
result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator)
}
}
}
return baseUniq(baseFlatten(result, 1), iteratee, comparator)
}
1.为什么用while不用for
2.为什么每次循环都从第一个开始比
就是为什么不用
for(let i=0;i<len;i++){
for(let j=i;j<len;j++){}
}
然后两个数组一对比就得到不同都值
就是
[1,2],[2,3]->[1,3]
而不是用_deffirence那种方式
[1,2],[2,3]->[1]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…