Suppose I have an array of object,
const book = [{'name':'alpha','readingTime':1231},{'name':'alpha','readingTime':1254},
{'name':'beta','readingTime':190},
{'name':'theta','readingTime':909},{'name':'theta','readingTime':10}]
I want to calculate average for each name, such that expected O/P is
**{alpha:1242.5, beta:190, theta:459.5}**
For this I tried as ,
let calculatedValue = book.reduce((acc,curr) => acc+curr.readingTime,0)/book.length
This gives me average for all the object.
I'm unable to form logic corresponding to it.
Any guidance would really be helpful. If anyone needs any further information please let me know.