javascript Sum all item in array which match same key [closed]

I have a JSON like this: [ { “faculty”:{ “_id”:”5f9c3e04e5a5423cec34b2e2″, “code”:”khmt”, “facultyName”…

The Odin Project – Fundamentals 4 Exercises – sumAll

I am stuck in the sumAll exercise from the Fundamentals 4 portion of the Odin Project. I managed to pass the test in which I need the result to be ‘ERROR’. However, I cannot figure out the correct …

How to group by, calculate sum and get average in JavaScript array?

I have array of object Expected result: I use reduce() method to group the objects in an array by ‘group’ and calulate sum: How to group object of Array by key ‘group’ and calulate average?. I tried: But Expected result: Answer You could simply use reduce to get the total of age groups. And use object.keys length to get the average of your total as new object from getAvg function. Demo: