I have two arrays of objects:
var arOne = [
{key: 'alpha', value: 5},
{key: 'beta', value: 11},
{key: 'gamma', value: 15},
{key: 'delta', value: 12},
{key: 'epsilon', value: 55}
{key: 'pony', value: 101}
]
var arTwo = [
{key: 'alpha', value: 5.5},
{key: 'beta', value: 11.5},
{key: 'gamma', value: 15.5},
{key: 'psi', value: 12.5},
{key: 'omega', value: 55.5}
]
I need to merge values into one array of arrays.
Case where the keys match: create an array with the key and append the value from arTwo to arOne.
Case where the keys do not match: if the key exists in arOne, I include the value from arOne and a 0 for arTwo. If the key exists in arTwo, I include a 0 for arOne and the value from arTwo.
Note that arOne and arTwo may be different sizes (see the pony key in arOne).
This is what the result should look like:
var result = [
['alpha', 5, 5.5],
['beta', 11, 11.5],
['gamma', 15, 15.5],
['delta', 12, 0],
['epsilon', 55, 0],
['pony', 101, 0],
['psi', 0, 12.5],
['omega', 0, 55.5],
]
I've been staring at this all day and scratched all my attempts. Any thoughts?
result, and the other looping through the second and adding new entries toresult.