I have three objects I need to iterate to check for duplicates to end up with a single object. If there are duplicates, I'd like to put them into an array so the user can select the best value so they all ultimately end up as strings or integers (or objects with strings/integers). They might look like this:
const a = {
first_name: 'Tom',
height: {
feet: 5,
inches: 0
}
}
const b = {
first_name: 'Thomas',
last_name: 'Walsh',
email: 'tomwalsh@domain.com',
height: {
feet: 6,
inches: 0
}
}
const c = {
email: 'tomwalsh@sample.edu'
}
The result would look like this:
const result = {
first_name: ['Tom', 'Thomas'],
last_name: 'Walsh',
email: ['tomwalsh@domain.com', 'tomwalsh@sample.edu'],
height: {
feet: [5, 6],
inches: 0
}
}
I have no idea if a
, b
, or c
would be the authority on keys so I have to assume an unknown set of key/value pairs, but it's definitely small (no more than 20 pairs, only 2-3 would be more than 3 levels deep, and each of those levels would be a maximum of 4-5 key/value pairs.
I can create a new object, iterate each of the three recursively, and dump the value or create an array of values, but that seems inefficient. Any suggestions?
I've got lodash in the project if needed. Thanks!