1 | import baseDifference from './_baseDifference';
|
2 | import baseFlatten from './_baseFlatten';
|
3 | import baseIteratee from './_baseIteratee';
|
4 | import isArrayLikeObject from './isArrayLikeObject';
|
5 | import last from './last';
|
6 | import rest from './rest';
|
7 |
|
8 | /**
|
9 | * This method is like `_.difference` except that it accepts `iteratee` which
|
10 | * is invoked for each element of `array` and `values` to generate the criterion
|
11 | * by which they're compared. Result values are chosen from the first array.
|
12 | * The iteratee is invoked with one argument: (value).
|
13 | *
|
14 | * @static
|
15 | * @memberOf _
|
16 | * @since 4.0.0
|
17 | * @category Array
|
18 | * @param {Array} array The array to inspect.
|
19 | * @param {...Array} [values] The values to exclude.
|
20 | * @param {Array|Function|Object|string} [iteratee=_.identity]
|
21 | * The iteratee invoked per element.
|
22 | * @returns {Array} Returns the new array of filtered values.
|
23 | * @example
|
24 | *
|
25 | * _.differenceBy([3.1, 2.2, 1.3], [4.4, 2.5], Math.floor);
|
26 | * // => [3.1, 1.3]
|
27 | *
|
28 | * // The `_.property` iteratee shorthand.
|
29 | * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
|
30 | * // => [{ 'x': 2 }]
|
31 | */
|
32 | var differenceBy = rest(function(array, values) {
|
33 | var iteratee = last(values);
|
34 | if (isArrayLikeObject(iteratee)) {
|
35 | iteratee = undefined;
|
36 | }
|
37 | return isArrayLikeObject(array)
|
38 | ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), baseIteratee(iteratee))
|
39 | : [];
|
40 | });
|
41 |
|
42 | export default differenceBy;
|