You can just combine the differences between the two items in two directions.
function absDifference(first, second) {
return _.union(_.difference(first, second), _.difference(second, first));
}
console.assert(absDifference(["a", "b"], ["a", "c"]).toString() == "b,c");
var a = ["js-email"], b = ["js-email", "form-group"];
console.assert(absDifference(a, b).toString() == "form-group");
If you want this to be available as part of _
library itself, throughout your project, then you can make use of _.mixin
like this
_.mixin({
absDifference: function(first, second) {
return _.union(_.difference(first, second), _.difference(second, first));
}
});
and then
console.assert(_.absDifference(["a", "b"], ["a", "c"]).toString() == "b,c");
var a = ["js-email"],
b = ["js-email", "form-group"];
console.assert(_.absDifference(a, b).toString() == "form-group");