-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
Copy pathdifferenceBy.js
39 lines (37 loc) · 1.33 KB
/
differenceBy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import baseDifference from './internal/baseDifference';
import baseFlatten from './internal/baseFlatten';
import baseIteratee from './internal/baseIteratee';
import isArrayLikeObject from './isArrayLikeObject';
import last from './last';
import rest from './rest';
/**
* This method is like `_.difference` except that it accepts `iteratee` which
* is invoked for each element of `array` and `values` to generate the criterion
* by which uniqueness is computed. The iteratee is invoked with one argument: (value).
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to inspect.
* @param {...Array} [values] The values to exclude.
* @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
* @returns {Array} Returns the new array of filtered values.
* @example
*
* _.differenceBy([3.1, 2.2, 1.3], [4.4, 2.5], Math.floor);
* // => [3.1, 1.3]
*
* // using the `_.property` iteratee shorthand
* _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
* // => [{ 'x': 2 }]
*/
var differenceBy = rest(function(array, values) {
var iteratee = last(values);
if (isArrayLikeObject(iteratee)) {
iteratee = undefined;
}
return isArrayLikeObject(array)
? baseDifference(array, baseFlatten(values, false, true), baseIteratee(iteratee))
: [];
});
export default differenceBy;