PageRenderTime 17ms CodeModel.GetById 14ms app.highlight 1ms RepoModel.GetById 2ms app.codeStats 0ms

/node_modules/lodash/differenceWith.js

https://bitbucket.org/coleman333/smartsite
JavaScript | 40 lines | 15 code | 2 blank | 23 comment | 1 complexity | 4cd1de4eceab7068c9e8caf5d331f007 MD5 | raw file
 1var baseDifference = require('./_baseDifference'),
 2    baseFlatten = require('./_baseFlatten'),
 3    baseRest = require('./_baseRest'),
 4    isArrayLikeObject = require('./isArrayLikeObject'),
 5    last = require('./last');
 6
 7/**
 8 * This method is like `_.difference` except that it accepts `comparator`
 9 * which is invoked to compare elements of `array` to `values`. The order and
10 * references of result values are determined by the first array. The comparator
11 * is invoked with two arguments: (arrVal, othVal).
12 *
13 * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
14 *
15 * @static
16 * @memberOf _
17 * @since 4.0.0
18 * @category Array
19 * @param {Array} array The array to inspect.
20 * @param {...Array} [values] The values to exclude.
21 * @param {Function} [comparator] The comparator invoked per element.
22 * @returns {Array} Returns the new array of filtered values.
23 * @example
24 *
25 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
26 *
27 * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
28 * // => [{ 'x': 2, 'y': 1 }]
29 */
30var differenceWith = baseRest(function(array, values) {
31  var comparator = last(values);
32  if (isArrayLikeObject(comparator)) {
33    comparator = undefined;
34  }
35  return isArrayLikeObject(array)
36    ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
37    : [];
38});
39
40module.exports = differenceWith;