I'm new to javascript, and I'm trying to learn more about working with array's so I built a grocery list builder, and I'm getting stuck on reducing the list if the user accidentally inserts an item twice.
I think the problem is that my reducing function isn't hitting the item selector, but I haven't been able to find any examples showing this kind of problem.
This is what I have for a reducing function:
function reducingFood() {
var reducedFood = myGroceries.reduce(function(obj, item) {
var itemName = item['item'];
if(!obj[itemName]) {
obj[itemName] = 0;
}
obj[itemName]++;
return obj;
}, {})
addStructure();
}
I setup a JSFiddle showing the full code: https://jsfiddle.net/Jon43/frvLc7Le/8/