[d565449] | 1 | import baseDifference from './_baseDifference.js';
|
---|
| 2 | import baseFlatten from './_baseFlatten.js';
|
---|
| 3 | import baseIteratee from './_baseIteratee.js';
|
---|
| 4 | import baseRest from './_baseRest.js';
|
---|
| 5 | import isArrayLikeObject from './isArrayLikeObject.js';
|
---|
| 6 | import last from './last.js';
|
---|
| 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. The order and references of result values are
|
---|
| 12 | * determined by the first array. The iteratee is invoked with one argument:
|
---|
| 13 | * (value).
|
---|
| 14 | *
|
---|
| 15 | * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
|
---|
| 16 | *
|
---|
| 17 | * @static
|
---|
| 18 | * @memberOf _
|
---|
| 19 | * @since 4.0.0
|
---|
| 20 | * @category Array
|
---|
| 21 | * @param {Array} array The array to inspect.
|
---|
| 22 | * @param {...Array} [values] The values to exclude.
|
---|
| 23 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
---|
| 24 | * @returns {Array} Returns the new array of filtered values.
|
---|
| 25 | * @example
|
---|
| 26 | *
|
---|
| 27 | * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
|
---|
| 28 | * // => [1.2]
|
---|
| 29 | *
|
---|
| 30 | * // The `_.property` iteratee shorthand.
|
---|
| 31 | * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
|
---|
| 32 | * // => [{ 'x': 2 }]
|
---|
| 33 | */
|
---|
| 34 | var differenceBy = baseRest(function(array, values) {
|
---|
| 35 | var iteratee = last(values);
|
---|
| 36 | if (isArrayLikeObject(iteratee)) {
|
---|
| 37 | iteratee = undefined;
|
---|
| 38 | }
|
---|
| 39 | return isArrayLikeObject(array)
|
---|
| 40 | ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), baseIteratee(iteratee, 2))
|
---|
| 41 | : [];
|
---|
| 42 | });
|
---|
| 43 |
|
---|
| 44 | export default differenceBy;
|
---|