Write a function named sort_by_average_rating that takes a list/array of objects/dictionaries as a parameter where each object/dictionary has "ratings", "budget", and "box_office" as keys. The values they associate with "budget" and "box_office" are integers and the value they associate with "ratings" is a list/array of integers. Sort the input based on the average of the numbers in the list/array associated with the key "ratings"Since this sorting is done 'in-place', your function does not need to return a value.
I want to use lambda function so I made the code. Please let me know what's wrong with my code. I know I have to make loop for sum of "ratings"
function sort_by_average_rating(x) {
x.sort((a) => { return sum(a.rating)/a.length})
return x
}
I need to find total sum of a.rating
Lets say {'rating': [1,2,3,4,5]}
the sum(a.rating)
should be 15
.