Check out this interesting plunker I have here...
I've noticed that when the 3rd item is deleted from the original, the calculation for total_expenses
comes out as 23196. However, when the third object is included, total_expenses
returns null. Is there something in my code that I might be overlooking?
The function total_expenses()
utilizes _.reduce
to sum up the values of a specific attribute across the collection.
$scope.loan.total_expenses = _.reduce(original, function(obj){
var grand = 0;
grand += obj.cost;
return grand;
});