My language is PHP, but the algorithm should be quite universal.
I have an associative array of ratings (let) and the number of times the rating has been assigned.
$ratings = array( 1 => 1, 2 => 3, 3 => 6, 4 => 3, 5 => 3 );
This is the equivalent: [1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5] , but given the number I am working with, it would be perfectly it is inefficient to convert from the first form to the second.
What will be the algorithm for calculating the average of the above numbers?
source share