Build a Smart Pantry Restocker - Build a Smart Pantry Restocker

Tell us what’s happening:

I’m having trouble with passing test 16 about how “the functions should work together to process a shipment”.
I’ve checked the GitHub and tried processing a shipment the same way it’s done there, but I can’t seem to pass this last test.

Your code so far

function parseShipment (rawData) {
  const ans = [];
  const skuSoFar = [];
  for (const data of rawData){
    const dataList = data.split("|");
    let [sku, name, qty, expires, zone] = dataList;
    if (!skuSoFar.includes(sku)) {
      ans.push({sku: sku, name: name, qty:Number(qty), expires: expires, zone: zone || "general"});
      skuSoFar.push(sku);
    }
  }
  return ans;
}

function planRestock (pantry, shipment) {
  let ans = [];
  let pantry_skus = [];
  for (const thing of pantry){
    pantry_skus.push(thing.sku);
  }
  for (const thing of shipment) {
    if (thing.qty <= 0) {
      ans.push({type: "discard", item: {sku: thing.sku,
         zone: thing.zone}});
    } else if (pantry_skus.includes(thing.sku)) {
      ans.push(
        {type: "restock", 
        item: {sku: thing.sku,
         zone: thing.zone}
        });
    } else {
      ans.push({type: "donate", item: {sku: thing.sku,
         zone: thing.zone}});
    }
  }
  return ans;
}

function groupByZone (actions) {
  let ans = {};
  for (const action of actions) {
    const zone = action.item.zone;
    if (!(zone in ans)) {
      ans[zone] = [];
    }
    ans[zone].push(action)
  }
  return ans;
}

function clonePantry (pantry) {
  const newPantry = JSON.parse(JSON.stringify(pantry));
  return newPantry;
}

const pantry = [
  { sku: "A10", name: "Tomatoes", qty: 4, expires: "2027-01-01", zone: "fridge" },
  { sku: "D43", name: "Pineapples", qty: 2, expires: "2020-01-01", zone: "general" }
];

const rawData = [
  "A10|Tomatoes|5|2027-01-01", 
  "B21|Bananas|10|2027-01-01", 
  "C32|Eggs|3|2027-01-01|fridge", 
  "C32|Eggs|3|2027-01-01", 
  "D43|Pineapples|0|2027-01-01", 
  "E54|Peppers|-1|2027-01-01|fridge"
];

const shipment = parseShipment(rawData);
const pantryCopy = clonePantry(pantry);
const actions = planRestock(pantryCopy, shipment);
const grouped = groupByZone(actions);

console.log(grouped);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36 Edg/148.0.0.0

Challenge Information:

Build a Smart Pantry Restocker - Build a Smart Pantry Restocker

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-smart-pantry-restocker/69a5f35669099ed52f8563b1.md at main · freeCodeCamp/freeCodeCamp · GitHub

After some thought I got the test to pass. I just had to change “{sku: thing.sku, zone: thing.zone}” to “thing” in my planRestock function.
For some reason I misinterpreted something in the GitHub to imply that only sku and zone were expected.