Smart pantry restocker - plan restock issue

Cuéntanos qué está pasando:

my function planRestock is returnning an array acordign to the instructions but still wont pass the test, maybe I am misunderstandig something, please help, I’m stuck in that part.

Tu código hasta ahora

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(data) {
  const res = []

  for (const elm of data) {
   let splited = elm.split("|");
    const obj = {
      sku: splited[0],
      name: splited[1],
      qty: +splited[2],
      expires: splited[3],
      zone: splited[4] || "general"
    }
    res.push(obj)
  }

  for (const obj of res) {
    let match = 0
    for (let i = 0 ; i < res.length ; i++) {
      
      if (obj.sku === res[i].sku) {
        match++
        if (match > 1) {
          res.splice(i, 1)
        }
      }
    }
  }

  return res
}

function planRestock(pantry, shipment) {
  const parsed = parseShipment(shipment)

  return parsed.map(item => {
    if (item.qty <= 0) {
      return {type: "discard", item}
    }

    const exists = pantry.some(p => p.sku === item.sku)
    return {
      type: exists ? "restock" : "donate",
      item
    }
  })
}

console.log(planRestock(pantry, rawData))

function groupByZone(actions) {
  const zones = {}
  for (const obj of actions) {
    let zone = obj.zone
    if (!zones[zone]) {
      zones[zone]
    }
    zones[zone] = []
    obj.zone === zones[zone] ? zones[zone].push(obj.type) : zones[zone]
  }
  return zones
}


function clonePantry(pantry) {
  const clone = {...pantry}
  return clone
}


Información de tu navegador:

El agente de usuario es: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36

Información del desafío:

Crear un reabastecedor inteligente de despensa - Construir un reabastecedor inteligente de despensa

Enlace de GitHub: i18n-curriculum/curriculum/challenges/espanol/blocks/lab-smart-pantry-restocker/69a5f35669099ed52f8563b1.md at main · freeCodeCamp/i18n-curriculum · GitHub

Welcome back @gers.e02,

Please add this code at the bottom of your script:

const pantryCopy = clonePantry(pantry);
console.log(pantryCopy)

Now compare the results to your pantry array of objects. Are they the same?

Should you be passing rawData to planRestock or what is returned from a call to parseShipment?

Happy coding