Let's say I have an array like this:
[
{
"player_id" => 1,
"number_of_matches" => 2,
"goals" => 5
},
{
"player_id" => 2,
"number_of_matches" => 4,
"goals" => 10
}
]
I want to have the average goals per match among all the players, not the average for each individual player, but the total average.
I have in mind doing it with .each
and storing each of the individual averages, and at the end add them all and divide by the number of players I have. However, I am looking for a Ruby/ one-liner way of doing this.