root / HServer / 00.Server / 00.Program / node_modules / lodash / differenceWith.js
이력 | 보기 | 이력해설 | 다운로드 (1.36 KB)
1 | 39 | HKM | var 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 | */
|
||
30 | var 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 | |||
40 | module.exports = differenceWith; |