mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 16:47:49 +00:00
Bump to v4.0.0.
This commit is contained in:
39
differenceBy.js
Normal file
39
differenceBy.js
Normal file
@@ -0,0 +1,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;
|
||||
Reference in New Issue
Block a user