I have data in the format
[
{
"timeline_map": {
"2017-05-06": 770,
"2017-05-07": 760,
"2017-05-08": 1250
...
}
},
{
"timeline_map": {
"2017-05-06": 590,
"2017-05-07": 210,
"2017-05-08": 300
...
}
},
{
"timeline_map": {
"2017-05-06": 890,
"2017-05-07": 2200,
"2017-05-08": 1032
...
}
}
]
that in order to use in a google chart I need to change to the format
[
["2017-05-06", 770, 590, 890, ...],
["2017-05-07", 760, 210, 2200, ...],
["2017-05-08", 1250, 300, 1032, ...]
]
I wrote the following to make the transformation
let mapped = _.map(
chartData.results[0].timeline_map, (timestampVal, timestampKey) => (
[timestampKey].concat(
_.map(
chartData.results, lineData => (
lineData.timeline_map[timestampKey]
)
)
)
)
)
This works, but I'm thinking that nesting the maps is not a good idea because how it will increase the amount of looping by the square off the length of the array being mapped. Is there a better way to achieve the desired result here.
["2017-05-06": 770, 590, 890, ...]this is no valid JS. Either[["2017-05-06", ...], ["2017-05-07", ...]]or{"2017-05-06": [...], "2017-05-07": [...]}. Wich one is it?: