I am trying to loop through 3 places and select the place with the highest average reviews and rating.
Say i have the following.
var places = [{
name: "place 1",
reviews: 100,
rating: 5,
},{
name: "place 2",
reviews: 10000,
rating: 5,
},{
name: "place 3",
reviews: 10000000,
rating: 4,
}];
for (i = 0; i < places.length; i++) {
// loop through and calculate the highest average reviews
var rating = places[i].rating;
var reviews = places[i].reviews;
// work out the average score place 3 should be the highest
}
http://jsbin.com/loyequluke/edit?js,console,output
Any suggestions what i want to do is find the highest average rating, out of the 3 places.
The correct result would be place 3, but i dont know how to work this out any help please?