I need to check if two object have common sub-objects. By common I mean that it exact same value, and not just equal values.
Something like:
function haveCommonObects(value1, value2) {
...
}
var common = {};
haveCommonObjects({a: common}, {b: {c: common}}) // true
haveCommonObjects({a: 1}, {b: 1}) // false
I need to check large objects, so function should be reasonable efficient.
Also I can't change objects, so I can't flag sub-objects with special property. Objects create in 3rd-party library so I can't alter Object.prototype
.
Ideal solution would be to get some kind of ID for every object and save it in collection that support fast lookup.
Can I make such function in JS?