mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 16:17:50 +00:00
Bump to v4.0.0.
This commit is contained in:
36
differenceWith.js
Normal file
36
differenceWith.js
Normal file
@@ -0,0 +1,36 @@
|
||||
import baseDifference from './internal/baseDifference';
|
||||
import baseFlatten from './internal/baseFlatten';
|
||||
import isArrayLikeObject from './isArrayLikeObject';
|
||||
import last from './last';
|
||||
import rest from './rest';
|
||||
|
||||
/**
|
||||
* This method is like `_.difference` except that it accepts `comparator`
|
||||
* which is invoked to compare elements of `array` to `values`. The comparator
|
||||
* is invoked with two arguments: (arrVal, othVal).
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Array
|
||||
* @param {Array} array The array to inspect.
|
||||
* @param {...Array} [values] The values to exclude.
|
||||
* @param {Function} [comparator] The comparator invoked per element.
|
||||
* @returns {Array} Returns the new array of filtered values.
|
||||
* @example
|
||||
*
|
||||
* var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
|
||||
*
|
||||
* _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
|
||||
* // => [{ 'x': 2, 'y': 1 }]
|
||||
*/
|
||||
var differenceWith = rest(function(array, values) {
|
||||
var comparator = last(values);
|
||||
if (isArrayLikeObject(comparator)) {
|
||||
comparator = undefined;
|
||||
}
|
||||
return isArrayLikeObject(array)
|
||||
? baseDifference(array, baseFlatten(values, false, true), undefined, comparator)
|
||||
: [];
|
||||
});
|
||||
|
||||
export default differenceWith;
|
||||
Reference in New Issue
Block a user