mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 18:17:48 +00:00
Ensure _.xor() returns new unique array.
This commit is contained in:
committed by
John-David Dalton
parent
c61a0cdd22
commit
64fc924357
@@ -5436,18 +5436,17 @@
|
|||||||
* // => [1, 4, 5]
|
* // => [1, 4, 5]
|
||||||
*/
|
*/
|
||||||
function xor() {
|
function xor() {
|
||||||
var index = -1,
|
var result,
|
||||||
|
index = -1,
|
||||||
length = arguments.length;
|
length = arguments.length;
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
var array = arguments[index];
|
var array = arguments[index];
|
||||||
if (isArray(array) || isArguments(array)) {
|
if (isArray(array) || isArguments(array)) {
|
||||||
var result = result
|
result = result ? baseDifference(result, array).concat(baseDifference(array, result)) : array;
|
||||||
? baseUniq(baseDifference(result, array).concat(baseDifference(array, result)))
|
|
||||||
: array;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result || [];
|
return result ? baseUniq(result) : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -8108,9 +8108,10 @@
|
|||||||
deepEqual(actual, [1, 4, 5]);
|
deepEqual(actual, [1, 4, 5]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should return an array of unique values', 1, function() {
|
test('should return an array of unique values', 2, function() {
|
||||||
var actual = _.xor([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]);
|
var actual = _.xor([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]);
|
||||||
deepEqual(actual, [1, 4, 5]);
|
deepEqual(actual, [1, 4, 5]);
|
||||||
|
deepEqual(_.xor([1, 1]), [1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should return a wrapped value when chaining', 2, function() {
|
test('should return a wrapped value when chaining', 2, function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user