mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 11:27:50 +00:00
Ensure _.xor works with more than two arrays. [closes #2758]
This commit is contained in:
23
lodash.js
23
lodash.js
@@ -4400,18 +4400,25 @@
|
|||||||
* @returns {Array} Returns the new array of values.
|
* @returns {Array} Returns the new array of values.
|
||||||
*/
|
*/
|
||||||
function baseXor(arrays, iteratee, comparator) {
|
function baseXor(arrays, iteratee, comparator) {
|
||||||
|
var length = arrays.length;
|
||||||
|
if (length < 2) {
|
||||||
|
return length ? baseUniq(arrays[0]) : [];
|
||||||
|
}
|
||||||
var index = -1,
|
var index = -1,
|
||||||
length = arrays.length;
|
result = Array(length);
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
var result = result
|
var array = arrays[index],
|
||||||
? arrayPush(
|
othIndex = -1;
|
||||||
baseDifference(result, arrays[index], iteratee, comparator),
|
|
||||||
baseDifference(arrays[index], result, iteratee, comparator)
|
while (++othIndex < length) {
|
||||||
)
|
var othArray = arrays[othIndex];
|
||||||
: arrays[index];
|
if (othArray !== array) {
|
||||||
|
result[index] = baseDifference(result[index] || array, othArray, iteratee, comparator);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return (result && result.length) ? baseUniq(result, iteratee, comparator) : [];
|
return baseUniq(baseFlatten(result, 1), iteratee, comparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -25264,7 +25264,7 @@
|
|||||||
assert.expect(2);
|
assert.expect(2);
|
||||||
|
|
||||||
var actual = func([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]);
|
var actual = func([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]);
|
||||||
assert.deepEqual(actual, [1, 4, 5]);
|
assert.deepEqual(actual, [1, 4]);
|
||||||
|
|
||||||
actual = func([1, 1]);
|
actual = func([1, 1]);
|
||||||
assert.deepEqual(actual, [1]);
|
assert.deepEqual(actual, [1]);
|
||||||
|
|||||||
Reference in New Issue
Block a user