mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 07:17:50 +00:00
35 lines
881 B
JavaScript
35 lines
881 B
JavaScript
import baseDifference from '../internal/baseDifference';
|
|
import baseUniq from '../internal/baseUniq';
|
|
import isArrayLike from '../internal/isArrayLike';
|
|
|
|
/**
|
|
* Creates an array of unique values that is the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
|
|
* of the provided arrays.
|
|
*
|
|
* @static
|
|
* @memberOf _
|
|
* @category Array
|
|
* @param {...Array} [arrays] The arrays to inspect.
|
|
* @returns {Array} Returns the new array of values.
|
|
* @example
|
|
*
|
|
* _.xor([1, 2], [4, 2]);
|
|
* // => [1, 4]
|
|
*/
|
|
function xor() {
|
|
var index = -1,
|
|
length = arguments.length;
|
|
|
|
while (++index < length) {
|
|
var array = arguments[index];
|
|
if (isArrayLike(array)) {
|
|
var result = result
|
|
? baseDifference(result, array).concat(baseDifference(array, result))
|
|
: array;
|
|
}
|
|
}
|
|
return result ? baseUniq(result) : [];
|
|
}
|
|
|
|
export default xor;
|