Below is my array of objects:
var filterStatus = [{ doc_count: 49, key: "Completed", color: "#1DC9B7" }, { doc_count: 147, key: "Failed", color: "#F14C69" }, { doc_count: 321, key: "In Progress", color: "#FFC568" }, { doc_count: 29, key: "Started" }];
I am looking to extract results that include the statuses Completed, Failed, and In Progress (Should also include Started status).
This is the code I am currently using:
var result = filterStatus.filter(obj => { if(obj.key == 'Started' || obj.key == 'In Progress'){ return obj}} ).map(obj => obj.doc_count).reduce((p, c) => p + c, 0);
The current result obtained is 350.
The expected output should be as follows:
[{ doc_count: 49, key: "Completed", color: "#1DC9B7" }, { doc_count: 147, key: "Failed", color: "#F14C69" }, { doc_count: 350, key: "In Progress", color: "#FFC568" }];
Note: The expected output includes an addition based on combining the counts for Started and In Progress under In Progress doc_count.