Build a Smart Pantry Restocker - Test 7

Tell us what’s happening:

I can’t pass the Test 7. The output appears to be what the test is looking for. May I kindly ask for your assistance on what I’m overlooking here?

Your code so far

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"
];

function parseShipment(rawData) {
  const finalData = [];
  const duplicateSKU = [];

  for (let i = 0; i < rawData.length; i++) {
    const perData = rawData[i].split("|");
    let [sku, name, qty, expires, zone] = perData;
    if(!duplicateSKU.includes(sku)) {
      finalData.push({sku: sku, name: name, qty: parseInt(qty), expires: expires, zone: zone || "general"});
      duplicateSKU.push(sku);
    }
  }

  return finalData;
}

function planRestock(pantry, shipment) {

  const goods = parseShipment(shipment);
  const finalData = [];
  const shipmentId = [];
  const pantryId = [];

  for (let i = 0; i < pantry.length; i++) {
    pantryId.push(pantry[i].sku);
  }

  for (let i = 0; i < goods.length; i++) {
    const perData = goods[i];
    shipmentId.push(perData.sku);

    if (perData.qty <= 0) {
      finalData.push({type: "discard", item: perData});
    } else if (pantryId.includes(shipmentId[i])) {
      finalData.push({type: "restock", item: perData});
    } else {
      finalData.push({type: "donate", item: perData});
    }
  }
  return finalData;
}

// console.log(pantry[0].sku.includes("A10"))
console.log(planRestock(pantry, rawData));

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) 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

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

Hi @develobray,

The functions are meant to work together.

Here you are passing rawData to planRestock, but planRestock is looking for shipment.

But when I change your code to this:

const shipment = parseShipment(rawData)
// console.log(pantry\[0\].sku.includes("A10"))
console.log(planRestock(pantry, shipment));

I see an error in the console:

TypeError: rawData[i].split is not a function

Happy coding

Thank you so much! At first I thought I have to put the parseShipment() inside of planRestock() scope. Glad I ask here.