Projekt

Obecné

Profil

Stáhnout (1.49 KB) Statistiky
| Větev: | Revize:
1
var 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
 */
34
var 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

    
44
module.exports = differenceBy;
(305-305/590)