Tell us what’s happening:
I am trying to create the groupByZone function calling it like so:
const actions = [
{ type: "restock", item: { sku: "A1", zone: "fridge" } },
{ type: "donate", item: { sku: "B1", zone: "fridge" } },
{ type: "discard", item: { sku: "C1", zone: "pantry" } },
];
console.log(const groupByZone(actions));
and am getting what I think is a correct result:
{ fridge: [ 'restock', 'donate' ], pantry: [ 'discard' ] }
But I get this error:
13. Your groupByZone function should correctly group actions with the right content and count.
What does it mean by count?
The instructions for this function are
- You should implement a groupByZone(actions) function that groups the actions into storage zones based on each item’s zone property.
The function should return an object where each key is a zone name and the value is an array of actions belonging to that zone.
For example, if actions contain items with zones “fridge” and “pantry”, the result should be { fridge: […], pantry: […] }.
No mention of count. Please advise.
Your code so far
const groupByZone = actions => {
const retObj = {};
actions.forEach(action => {
if (retObj.hasOwnProperty(action.item.zone)) {
retObj[action.item.zone].push(action.type);
} else {
retObj[action.item.zone] = [action.type];
}
})
return retObj;
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:152.0) Gecko/20100101 Firefox/152.0
Challenge Information:
Build a Smart Pantry Restocker - Build a Smart Pantry Restocker