Build a Smart Pantry Restocker - Build a Smart Pantry Restocker

Tell us what’s happening:

hi,what im doing wrong? Your parseShipment function should convert shipment strings in the array into objects with the properties: sku, name, qty, expires, and zone.
3. Duplicate SKUs in the shipment should be ignored.
5. The qty value should be converted into a number.
13. You should define a function named clonePantry that accepts one parameter called pantry.
14. clonePantry should return a new array instead of the original pantry array.
15. The objects inside the cloned pantry should also be

Your code so far

function parseShipment(rawData) {
  const parsedItems = [];
  const seenSkus = new Set();

  for (const line of rawData) {
    if (!line || !line.trim()) continue;

    const parts = line.split(',').map((part) => part.trim());
    const sku = parts[0] || '';

    if (!sku || seenSkus.has(sku)) {
      continue;
    }
    seenSkus.add(sku);

    const name = parts[1] || '';
    const qty = Number(parts[2] || 0);
    const expires = parts[3] || '';
    const zone = parts[4] || 'general';

    parsedItems.push({ sku, name, qty, expires, zone });
  }
  return parsedItems;
}

function planRestock(pantry, shipment) {
  const actions = [];

  for (const item of shipment) {
    const existsInPantry = pantry.some((p) => p.sku === item.sku);

    let actionType = 'donate';
    if (item.qty <= 0) {
      actionType = 'discard';
    } else if (existsInPantry) {
      actionType = 'restock';
    }

    actions.push({ type: actionType, item });
  }

  return actions;
}

function groupByZone(actions) {
  return actions.reduce((grouped, action) => {
    const zone = action.item.zone || 'general';
    if (!grouped[zone]) grouped[zone] = [];
    grouped[zone].push(action);
    return 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

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

Here, try to test your code by running this:

console.log(parseShipment([
  "A10|Tomatoes|5|2027-01-01", // Restock existing item
  "B21|Bananas|10|2027-01-01", // Donate new item without zone
  "C32|Eggs|3|2027-01-01|fridge", // Donate to a defined zone
]));

The sku is the first field (like A10), name is the 2nd field, quantity is next, then the expiry.