I'm new to javascript, I have array object, which has keys total,failure with there respective integer values. I want to add the total of all the array objects and also want to derive total percentage of failure out of total sum up value
With javascript reduce function, I'm able to add the total of all array objects, but not able to get percentage of failure to total sum up value. Please do suggest here with your valuable input
Here is my code below :
var data = [
{"total":728, "failure": 76},
{"total":708, "failure": 56},
{"total":435, "failure": 36},
{"total":324, "failure": 93},
{"total":649, "failure": 65}
]
var r = data.reduce((a, b) => ({total: a.total + b.total}));
console.log(r)
Here with reduce function, I"m able to add total and getting the count, now I need failure in percent to total count using reduce function. Please suggest