mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 23:57:49 +00:00
Issue #309, adding symmetric difference as _.symDifference, and making _.difference accept any number of arguments.
This commit is contained in:
@@ -402,10 +402,19 @@
|
||||
});
|
||||
};
|
||||
|
||||
// Take the difference between one array and another.
|
||||
// Take the difference between one array and a number of other arrays.
|
||||
// Only the elements present in just the first array will remain.
|
||||
_.difference = function(array, other) {
|
||||
return _.filter(array, function(value){ return !_.include(other, value); });
|
||||
_.difference = function(array) {
|
||||
var rest = _.flatten(slice.call(arguments, 1));
|
||||
return _.filter(array, function(value){ return !_.include(rest, value); });
|
||||
};
|
||||
|
||||
// Take the symmetric difference between a list of arrays. Only the elements
|
||||
// present in one of the input arrays will remain.
|
||||
_.symDifference = function() {
|
||||
return _.reduce(arguments, function(memo, array) {
|
||||
return _.union(_.difference(memo, array), _.difference(array, memo));
|
||||
});
|
||||
};
|
||||
|
||||
// Zip together multiple lists into a single array -- elements that share
|
||||
|
||||
Reference in New Issue
Block a user