I have the following code and it matches my requirements, however, it is not modular and not generic. For example, I might have a hundred of stats objects. Is there a way to make it more generic?
Actually, in dataSeries I have only two arrays of objects. And I am sorting them based on their color (red, green). Therefore, there are only four stats objects initialized.
var stats1 = {data: []}
var stats2 = {data: []}
var stats3 = {data: []}
var stats4 = {data: []}
stats1.data.push(self.dataSeries[0].data.filter(function (x) { return x.color == "green" }))
stats2.data.push(self.dataSeries[0].data.filter(function (x) { return x.color == "red" }))
stats3.data.push(self.dataSeries[1].data.filter(function (x) { return x.color == "green" }))
stats4.data.push(self.dataSeries[1].data.filter(function (x) { return x.color == "red" }))
a=[{ data: stats1.data[0] }, { data: stats2.data[0] }, { data: stats3.data[0] }, { data: stats4.data[0] }];
selfhere?