1 | import arrayFilter from './_arrayFilter.js';
|
---|
2 | import baseRest from './_baseRest.js';
|
---|
3 | import baseXor from './_baseXor.js';
|
---|
4 | import isArrayLikeObject from './isArrayLikeObject.js';
|
---|
5 | import last from './last.js';
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * This method is like `_.xor` except that it accepts `comparator` which is
|
---|
9 | * invoked to compare elements of `arrays`. The order of result values is
|
---|
10 | * determined by the order they occur in the arrays. The comparator is invoked
|
---|
11 | * with two arguments: (arrVal, othVal).
|
---|
12 | *
|
---|
13 | * @static
|
---|
14 | * @memberOf _
|
---|
15 | * @since 4.0.0
|
---|
16 | * @category Array
|
---|
17 | * @param {...Array} [arrays] The arrays to inspect.
|
---|
18 | * @param {Function} [comparator] The comparator invoked per element.
|
---|
19 | * @returns {Array} Returns the new array of filtered values.
|
---|
20 | * @example
|
---|
21 | *
|
---|
22 | * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
|
---|
23 | * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
|
---|
24 | *
|
---|
25 | * _.xorWith(objects, others, _.isEqual);
|
---|
26 | * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
|
---|
27 | */
|
---|
28 | var xorWith = baseRest(function(arrays) {
|
---|
29 | var comparator = last(arrays);
|
---|
30 | comparator = typeof comparator == 'function' ? comparator : undefined;
|
---|
31 | return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
|
---|
32 | });
|
---|
33 |
|
---|
34 | export default xorWith;
|
---|