Tell us what’s happening:
I had to verify the github link submitted in another hint; however, the problem is that the structure of the actions array elements is different from any result of a function. Please advise I dont know how to proceed
Your code so far
function parseShipment(rawData) {
let result = [];
let skus = []
for (let element of rawData) {
let separated = element.split("|");
if (skus.includes(separated[0])) {
continue
}
let newObj = {};
newObj.sku = separated[0];
skus.push(separated[0]);
newObj.name = separated[1];
newObj.qty = Number(separated[2]);
newObj.expires = separated[3];
separated.length === 5 ? newObj.zone = separated[4] : newObj.zone = "general";
result.push(newObj)
}
return result
}
function planRestock(pantry, shipment) {
let result = [];
let skus = [];
for (let product of shipment) {
let newObj = {};
if (product.qty <= 0) {
newObj.type = "discard";
newObj.item = product.name;
result.push(newObj);
continue
}
else if (pantry.length === 0 && product.qty > 0) {
newObj.type = "donate";
newObj.item = product.name;
result.push(newObj);
continue
}
for (let item of pantry) {
if (product.sku === item.sku) {
newObj.type = "restock";
newObj.item = product.name;
result.push(newObj);
break;
}
}
}
return result
}
function groupByZone(actions) {
let result = {};
for (let action of actions) {
let zone = action.item.zone;
if (!result.hasOwnProperty(zone)) {
result[zone] = [];
result[zone].push(action)
continue
}
result[zone].push(action)
}
return result
}
function clonePantry(pantry) {
return structuredClone(pantry)
}
const rawData = ["A10|Tomatoes|5|2027-01-01|fridge"];
const pantry = [{ sku: "A10", name: "Tomatoes", qty: 4, expires: "2027-01-01", zone: "fridge" }];
let shipment = parseShipment(rawData);
let clonedPantry = clonePantry(pantry);
let plannedRestock = planRestock(clonedPantry, shipment);
console.log(groupByZone(plannedRestock))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36
Challenge Information:
Build a Smart Pantry Restocker - Build a Smart Pantry Restocker