Hello there, I am currently in the process of creating an array.
this.data = [{
label: 'Total',
count: details.request.length,
}, {
label: 'In-Progress',
count: details.request.filter((obj) =>
obj.statusId === 0 ||
obj.statusId === 1 ||
obj.statusId === 3 ||
obj.statusId === 4
? obj
: null,
).length,
}, {
label: 'Success',
count: details.request.filter(({ statusId }) =>
statusId === 6 ? statusId : null,
).length,
additionalObj: details.request.filter((obj) =>
obj.statusId === 6 ? obj : null,
),
}, {
label: 'Failed',
count: details.request.filter(({ statusId }) =>
statusId === 2 || statusId === 5 ? statusId : null,
).length,
additionalObj: details.request.filter((obj) =>
obj.statusId === 2 || obj.statusId === 5 ? obj : null,
),
}];
I have structured the array as required but I believe there is room for optimization. I find myself using the array filter method multiple times to calculate both the count and additionalObj properties. I am open to suggestions on how I can use the filter method more efficiently for both calculations. Any assistance would be greatly appreciated.
Just so you know, this is what the details structure looks like:
details = {
request: []
}