Skip to content

Instantly share code, notes, and snippets.

@madhums
Created August 21, 2012 18:04
Show Gist options
  • Save madhums/3417964 to your computer and use it in GitHub Desktop.
Save madhums/3417964 to your computer and use it in GitHub Desktop.
intersection of array of objects
_.intersectionObjects = _.intersect = function(array) {
var slice = Array.prototype.slice; // added this line as a utility
var rest = slice.call(arguments, 1);
return _.filter(_.uniq(array), function(item) {
return _.every(rest, function(other) {
//return _.indexOf(other, item) >= 0;
return _.any(other, function(element) { return _.isEqual(element, item); });
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment