Ensure _.xor() returns new unique array.

This commit is contained in:
Ryan Van Etten
2013-12-06 20:59:25 -05:00
committed by John-David Dalton
parent c61a0cdd22
commit 64fc924357
2 changed files with 6 additions and 6 deletions

View File

@@ -5436,18 +5436,17 @@
* // => [1, 4, 5]
*/
function xor() {
var index = -1,
var result,
index = -1,
length = arguments.length;
while (++index < length) {
var array = arguments[index];
if (isArray(array) || isArguments(array)) {
var result = result
? baseUniq(baseDifference(result, array).concat(baseDifference(array, result)))
: array;
result = result ? baseDifference(result, array).concat(baseDifference(array, result)) : array;
}
}
return result || [];
return result ? baseUniq(result) : [];
}
/**

View File

@@ -8108,9 +8108,10 @@
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]);
deepEqual(actual, [1, 4, 5]);
deepEqual(_.xor([1, 1]), [1]);
});
test('should return a wrapped value when chaining', 2, function() {