I'm struggling to find an elegant and reliable way of merging two arrays in vanilla JS or d3.js, where
- the "rows" of the series do not necessarily match;
- objects may share some but not all attributes;
- "missing" attributes are filled in as null.
For example, two arrays of the form
A =
[
{
year : 2001,
gdp : 1.1,
population : 1100
},
{
year : 2002,
gdp : 1.2,
population : 1200
},
]
B =
[
{
year : 2000,
gdp : 1.0,
rainfall : 100
},
{
year : 2001,
gdp : 1.1,
rainfall : 110
}
]
would ideally combine to give
C =
[
{
year : 2000,
gdp : 1.0,
population : null,
rainfall : 10
},
{
year : 2001,
gdp : 1.1,
population : 1100,
rainfall : 110
},
{
year : 2002,
gdp : 1.2,
population : 1200,
rainfall : null
},
]
I can usually figure this kind of thing out but this one has got me really stuck!
gdpa fixed value or dynamic? what have you tried?