I have two JavaScript objects (of arbitrary depth) that have much of the same information.
I'm looking for help getting the shared data between two objects.
For example:
const a = {
name: 'Alice',
features: {
speed: 3,
strength: 90,
mind: {
power: 42
}
}
};
const b = {
name: 'Bob',
features: {
speed: 3,
stamina: 1,
mind: {
power: 42,
flexibility: 0,
telekinesis: 42
}
}
};
My goal is to come up with a solution to produce the data that they share:
const shared = {
features: {
speed: 3,
mind: {
power: 42
}
}
}
The real data I'm operating on is nested arbitrarily deep (often dozens of objects within objects), but I'm hoping the above examples are helpful.
This is a one-off task so I'm not particularly concerned with performance, and I'm happy to use any library as long as it works. Thanks for the help!