By default, reduce
starts out with the first two items in the list, so s
will be the first item in the array and entry
will be the second item the first time your function is called. Give it a value to start with:
var s = _.reduce(groupBy.Food, function(s, entry) {
return s + parseFloat(entry.amount);
}, 0);
(Array
’s reduce
behaves the same way.)