Question

I have two objects A and B. I want to know if they share the keys x and y.

I wrote this:

function sharesKeys(keys, objA, objB) {
    return _.every(keys, function (key) {
        return key in objA && key in objB;
    });
}

to be called as:

if (sharesKeys(['x', 'y'], cellA, cellB)) { ...

but want to know if I am missing a lo-dash method to do this directly.

Was it helpful?

Solution

As already stated by @Bergi, you're fine to do that, because there's no such function in Lo-Dash.

As a suggestion, you could test if N objects share that keys, and not only 2!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top