Here is a sample of the data I have:
data = [
[
{"name":"cpumhz","data":[[1433856538,0],[1433856598,0]]},
{"name":"mem","data":[[1433856538,13660],[1433856598,13660]]}
],
[
{"name":"cpumhz","data":[[1433856538,0],[1433856598,0]]},
{"name":"mem","data":[[1433856538,13660],[1433856598,13660]]}
],
[
{"name":"cpumhz","data":[[1433856538,0],[1433856598,0]]},
{"name":"mem","data":[[1433856538,13660],[1433856598,13660]]}
]
];
My question is how to utilize map to merge the arrays so that the data
values are combined:
For example:
data = [
[
{"name":"cpumhz","data":[[1433856538,0],[1433856598,0],[1433856538,0],[1433856598,0], [1433856538,0],[1433856598,0]]},
{"name":"mem","data":[[1433856538,13660],[1433856598,13660], [1433856538,13660],[1433856598,13660], [1433856538,13660],[1433856598,13660]]}
]
];
I have been attempting to achieve this manually as follows:
res = []
cpudata = _.flatten([data[0][0].data, data[1][0].data, data[2][0].data])
res.push({name: 'cpumhz', data: cpudata})
memdata = _.flatten([data[0][1].data, data[1][1].data, data[2][1].data])
res.push({name: 'mem', data: memdata})
Link to the corresponding exercise: http://jsbin.com/bekodirili/7/edit