UNPKG

1.06 kBJavaScriptView Raw
1import baseDifference from './_baseDifference.js';
2import baseFlatten from './_baseFlatten.js';
3import baseRest from './_baseRest.js';
4import isArrayLikeObject from './isArrayLikeObject.js';
5
6/**
7 * Creates an array of `array` values not included in the other given arrays
8 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
9 * for equality comparisons. The order and references of result values are
10 * determined by the first array.
11 *
12 * **Note:** Unlike `_.pullAll`, this method returns a new array.
13 *
14 * @static
15 * @memberOf _
16 * @since 0.1.0
17 * @category Array
18 * @param {Array} array The array to inspect.
19 * @param {...Array} [values] The values to exclude.
20 * @returns {Array} Returns the new array of filtered values.
21 * @see _.without, _.xor
22 * @example
23 *
24 * _.difference([2, 1], [2, 3]);
25 * // => [1]
26 */
27var difference = baseRest(function(array, values) {
28 return isArrayLikeObject(array)
29 ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
30 : [];
31});
32
33export default difference;