UNPKG

1.2 kBJavaScriptView Raw
1import arrayFilter from './_arrayFilter';
2import baseIteratee from './_baseIteratee';
3import baseXor from './_baseXor';
4import isArrayLikeObject from './isArrayLikeObject';
5import last from './last';
6import rest from './rest';
7
8/**
9 * This method is like `_.xor` except that it accepts `iteratee` which is
10 * invoked for each element of each `arrays` to generate the criterion by
11 * which by which they're compared. The iteratee is invoked with one argument:
12 * (value).
13 *
14 * @static
15 * @memberOf _
16 * @since 4.0.0
17 * @category Array
18 * @param {...Array} [arrays] The arrays to inspect.
19 * @param {Array|Function|Object|string} [iteratee=_.identity]
20 * The iteratee invoked per element.
21 * @returns {Array} Returns the new array of values.
22 * @example
23 *
24 * _.xorBy([2.1, 1.2], [4.3, 2.4], Math.floor);
25 * // => [1.2, 4.3]
26 *
27 * // The `_.property` iteratee shorthand.
28 * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
29 * // => [{ 'x': 2 }]
30 */
31var xorBy = rest(function(arrays) {
32 var iteratee = last(arrays);
33 if (isArrayLikeObject(iteratee)) {
34 iteratee = undefined;
35 }
36 return baseXor(arrayFilter(arrays, isArrayLikeObject), baseIteratee(iteratee));
37});
38
39export default xorBy;