Underscore provides handy function for array intersection, difference and union. But they don't work as expected for array of objects:
var first = {val: 1};
var otherFirst = {val: 1};
var second = {val: 2};
_.difference([first, second], [otherFirst]); // result is [first, second] instead of [second]
This happens because JS checks objects for reference equality. How can I intersect two arrays of objects?
I'm looking for some kind of idiomatic solution.