Tell us what’s happening:
I don’t understand the 4th step on the assignment, it says i should implement a function that ‘groups’ the actions into storage zones based on each item’s zone property. The thing is, what is ‘group’ in Java Script? Separate by arrays? Make a new object property ? What should it return? Should i compare the names of the items on action to the pantry, then what? I simply don’t even know what I’m being asked to do. The description is too vague, it doesn’t point to any wanted format of data, it just says i need to ‘group’ a list of objects by a property.
Your code so far
const rawData = [
"A10|Tomatoes|5|2027-01-01", // no zone field
"B21|Bananas|10|2027-01-01|fridge", // zone: "fridge"
"C32|Eggs|3|2027-01-01|pantry", // zone: "pantry"
];
const parseShipment = rawData => {
let parsedShipment = [];
let preParsed = [];
for (let item of rawData) {
preParsed.push(item.split("|"));
}
for (let item of preParsed) {
if(parsedShipment.some(obj => obj.sku === item[0])) {
continue;
}
if(!item[4]) {item[4] = "general"}
parsedShipment.push({sku: item[0],
name: item[1],
qty: Number(item[2]),
expires: item[3],
zone: item[4]})
}
return parsedShipment;
};
const planRestock = (pantry, shipment) => {
let actions = [];
for (let i = 0; i < shipment.length; i++) {
let item = shipment[i];
if (item.qty <= 0) {
actions.push({type: "discard", item: item.name})
continue;
}
if (pantry.some(obj => obj.sku === item.sku)) {
actions.push({type: "restock", item: item.name})
continue;
}
else {
actions.push({type: "donate", item: item.name})
continue;
}
}
return actions;
};
const groupByZone = actions => {
}
let pantry = [{ sku: 'A10', name: 'Tomatoes', qty: 3, expires: '2027/10/10', zone: 'general' },{ sku: 'B21', name: 'Bisquit', qty: 2, expires: '2027/10/10', zone: 'pantry' }]
let shipment = parseShipment(rawData);
console.log(planRestock(pantry, shipment))
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:151.0) Gecko/20100101 Firefox/151.0
Challenge Information:
Build a Smart Pantry Restocker - Build a Smart Pantry Restocker