79631136

Date: 2025-05-20 20:42:36
Score: 1
Natty:
Report link

this will calculate both the total amount purchased by the customers and the average

function averageAmountSpent(arr) {
  const total = {}
  const count = {}
  arr.forEach(item => {
    const customer = item.customer
    total[customer] = (total[customer] || 0) + item.amount
    count[customer] = (count[customer] || 0) + 1
  });
 
  const average = {}
  for (const customer in total) {
    average[customer] = total[customer] / count[customer]
  }
  return average
}
Reasons:
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: user18977478