const arr = inteviewDetails.qualityQuestions.reduce((res, curr, index) => { const key = res.find(r => r.key === curr?.qualityAttribute?.key) const score = { ...curr, score: application?.assessments?.["2nd-interview"]?.[index] } if (key) { key.stack.push(score) } else { res.push({ key: curr?.qualityAttribute?.key, stack: [score], name: curr.qualityAttribute.name, }) } return res }, []).map(item => { let seredne = (item?.stack || []).reduce((r, it) => r + parseFloat(it.score), 0) / (item?.stack || []).length; return { ...item, seredne }; });