1 | import baseDifference from './_baseDifference';
|
2 | import baseFlatten from './_baseFlatten';
|
3 | import isArrayLikeObject from './isArrayLikeObject';
|
4 | import last from './last';
|
5 | import rest from './rest';
|
6 |
|
7 | /**
|
8 | * This method is like `_.difference` except that it accepts `comparator`
|
9 | * which is invoked to compare elements of `array` to `values`. Result values
|
10 | * are chosen from the first array. The comparator is invoked with two arguments:
|
11 | * (arrVal, othVal).
|
12 | *
|
13 | * @static
|
14 | * @memberOf _
|
15 | * @since 4.0.0
|
16 | * @category Array
|
17 | * @param {Array} array The array to inspect.
|
18 | * @param {...Array} [values] The values to exclude.
|
19 | * @param {Function} [comparator] The comparator invoked per element.
|
20 | * @returns {Array} Returns the new array of filtered values.
|
21 | * @example
|
22 | *
|
23 | * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
|
24 | *
|
25 | * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
|
26 | * // => [{ 'x': 2, 'y': 1 }]
|
27 | */
|
28 | var differenceWith = rest(function(array, values) {
|
29 | var comparator = last(values);
|
30 | if (isArrayLikeObject(comparator)) {
|
31 | comparator = undefined;
|
32 | }
|
33 | return isArrayLikeObject(array)
|
34 | ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
|
35 | : [];
|
36 | });
|
37 |
|
38 | export default differenceWith;
|