I am struggling to come up with a way for format this data.
Desired Return: An object with 3 arrays
- a unique array of dates
- an array of data1 values the same length as the
datesarray, withnulland the index that corresponds with the index in thedatesarray for whichdata1does not have a value - the same as 2, except for data1 values
The example shown below should give a better idea of what I am trying to solve.
Desired Result:
{ dates: ['Tue Jun 20 2018',
'Wed Jun 21 2018',
'Thu Jun 22 2018',
'Fri Jun 23 2018',
'Sat Jun 24 2018'],
data1: [5, null, 12, null, 20]
data2: [14, 4, 15, 2, null]
}
Example Input:
An array with multiple objects.
Each object has a dates property
[
{ dates: ['Tue Jun 20 2018',
'Thu Jun 22 2018',
'Sat Jun 24 2018'],
data1: [5, 12, 20]
},
{ dates: ['Tue Jun 20 2018',
'Wed Jun 21 2018',
'Thu Jun 22 2018',
'Fri Jun 23 2018'],
data2: [14, 4, 15, 2]
}
]
I can solve by creating two objects key value pairs for each input object, joining all dates into an array and making unique, mapping over the new dates array and inserting null values in each data array if that specific object does not have that date as a key.
Sorry for the long/ confusing explanation. Have a look at the input/ output and let me know how I can best solve this.
Thanks!