I have a array of objects – something like this:
[
{"name" : "blar", "percentageTotal" : "10", "mostPopular" : "false", "leastPopular" : "false"},
{"name" : "foo", "percentageTotal" : "40", "mostPopular" : "false", "leastPopular" : "false"},
{"name" : "bar", "percentageTotal" : "50", "mostPopular" : "false", "leastPopular" : "false"}
]
What would the best way to iterate over the objects and update the “mostPopular” and “leastPopular” properties, based on the “percentageTotal” property?
In one pass find the index of the most and least popular items by max/min “percentageTotal” setting the most/least popular attributes to false, then set the most/least popular from the stored indices.
This solution does not require the names to be unique. You might get a small performance boost by setting
it=items[i]and using it instead.