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
}