I'm currently trying to map and reduce functions to flatten out a multidimensional array.
This is a mock example data set:
data: [
{
label: "Sort-01"
data: [
{
label: "OCT-2017"
weight: 2304
},
{
label: "NOV-2017"
weight: 1783
}
]
},
{
label: "Sort-02"
data: [
{
label: "OCT-2017"
weight: 4785
},
{
label: "NOV-2017"
weight: 102
}
]
},
......
]
I know in order to map-reduce by sort number I can use:
data.map(sort => sort.data.reduce((a,b) => a.weight + b.weight));
However, I want to reduce by the month instead of sort number.
I would appreciate any help.
Thanks,
Jay