Have a set of objects stored in an array. If I want to compare an attribute like weight, how would I do it in the most effective way? Let's say i want the fruitbasket to be full when weight = 10.
var fruitBasket = []
function addFruit(fruit, weight) {
return {
fruit: fruit,
weight: weight
}
}
fruitBasket.push(addFruit(apple, 2));
fruitBasket.push(addFruit(orange, 3));
fruitBasket.push(addFruit(watermelon, 5));
//etc...
Array.prototype.reducewith a function that adds theweightproperties.