"sideCardInfo": {
"title": "Hospital Admission",
"reportTitle": "Hospital Admission Report",
"subTitle": "Per 1000 Members",
"dateFilter": [
{
"date": previousYearRange,
"value": calculateAverage(allInsightData.map(obj => Number(obj.hospital_admissions_cnt_py))),
},
{
"date": currentYearRange,
"value": calculateAverage(allInsightData.map(obj => Number(obj.hospital_admissions_cnt))),
}
],
"percentage": calculatePercentage( calculateAverage(allInsightData.map(obj => Number(obj.hospital_admissions_cnt_py))), calculateAverage(allInsightData.map(obj => Number(obj.hospital_admissions_cnt)))),
"tooltipText": ""
},
In the above object inside dateFilter for value i am using a calculateAverage function to get the value i need to pass the same value as parameter for calculatePercentage which is a value for percentage key in the same object how to store the calculateAverage at dateFilter and pass it to calculatePercentage so that i can avoid calculating average two times