SIGN IN SIGN UP

A modern JavaScript utility library delivering modularity, performance, & extras.

0 0 9 JavaScript
2016-07-24 09:52:04 -07:00
define(['./_baseDifference', './_baseFlatten', './_baseRest', './isArrayLikeObject', './last'], function(baseDifference, baseFlatten, baseRest, isArrayLikeObject, last) {
2015-12-16 17:53:20 -08:00
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/**
* This method is like `_.difference` except that it accepts `comparator`
2016-09-17 22:24:52 -07:00
* which is invoked to compare elements of `array` to `values`. The order and
* references of result values are determined by the first array. The comparator
* is invoked with two arguments: (arrVal, othVal).
2015-12-16 17:53:20 -08:00
*
2016-07-24 09:52:04 -07:00
* **Note:** Unlike `_.pullAllWith`, this method returns a new array.
*
2015-12-16 17:53:20 -08:00
* @static
* @memberOf _
2016-03-26 00:00:01 -07:00
* @since 4.0.0
2015-12-16 17:53:20 -08:00
* @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 }]
*/
2016-07-24 09:52:04 -07:00
var differenceWith = baseRest(function(array, values) {
2015-12-16 17:53:20 -08:00
var comparator = last(values);
if (isArrayLikeObject(comparator)) {
comparator = undefined;
}
return isArrayLikeObject(array)
2016-04-07 21:35:23 -07:00
? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
2015-12-16 17:53:20 -08:00
: [];
});
return differenceWith;
});