# xorWith
# Description
该方法是像 xor,除了它接受一个 comparator ,以调用比较数组的元素。 comparator 调用 2 个参数:(arrVal, othVal).
# Params
(...arrays)
# Return
Array
# Depend
import baseXor from './.internal/baseXor.js'
import isArrayLikeObject from './isArrayLikeObject.js'
import last from './last.js'
# Code
function xorWith(...arrays) {
let comparator = last(arrays)
comparator = typeof comparator === 'function' ? comparator : undefined
return baseXor(arrays.filter(isArrayLikeObject), undefined, comparator)
}
# Analyze
和 xorBy 基本一致,除了传递给 baseXor
的参数是 comparator
, 也就是比较函数
# Example
console.log(xorWith([1,3],[2,4],[5,6], (x,y) => x > ++y)) // [ 1, 2 ]