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

/node_modules/lodash/differenceBy.js

https://bitbucket.org/coleman333/smartsite
JavaScript | 44 lines | 16 code | 2 blank | 26 comment | 1 complexity | 60b1d6dcb332ba0872a181e0e5849001 MD5 | raw file
 1var baseDifference = require('./_baseDifference'),
 2    baseFlatten = require('./_baseFlatten'),
 3    baseIteratee = require('./_baseIteratee'),
 4    baseRest = require('./_baseRest'),
 5    isArrayLikeObject = require('./isArrayLikeObject'),
 6    last = require('./last');
 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 */
34var 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
44module.exports = differenceBy;