Skip to content

Lab: Smart Pantry Restocker - Test 12 clarification #67842

@YourKindAlly

Description

@YourKindAlly

Describe the Issue

  • Test 12 is not descriptive enough with what an action is in this context. Is actions an array with objects? What objects? It would be helpful with an example of what the output of the groupByZone function should have as output.
  • A more descriptive or more through test to give more context with where the issue occurs.

Affected Page

https://www.freecodecamp.org/learn/javascript-v9/lab-smart-pantry-restocker/lab-smart-pantry-restocker

Your code

const rawData = [
  "A10|Tomatoes|5|2027-01-01",        // no zone field
  "B21|Bananas|10|2027-01-01|fridge", // zone: "fridge"
  "C32|Eggs|3|2027-01-01|pantry",     // zone: "pantry"
];

function parseShipment(rawData) {
  const parsedData = [];
  for (const row of rawData) {
    const columns = row.split("|");
    
    let isSameSKU = false;
    for (const comparison of parsedData) {
      if (comparison.sku === columns[0]) {
        isSameSKU = true;
      }
    }

    if (isSameSKU) {
      continue;
    }

    const data = {
      sku: columns[0],
      name: columns[1],
      qty: parseInt(columns[2]),
      expires: columns[3],
      zone: "general"
    };
    
    if (columns.length === 5) {
      data.zone = columns[4];
    }

    parsedData.push(data);
  }
  return parsedData;
}

function planRestock(pantry, shipment) {
  let collection = [];

  for (const row of shipment) {
    if (row.qty <= 0) {
      const index = {
        type: "discard",
        item: row
      };
      collection.push(index);
      continue;
    }

    for (const shelf of pantry) {
      if (shelf.sku === row.sku) {
        const index = {
          type: "restock",
          item: row
        };
        collection.push(index);
        continue;
      }
    }

    const index = {
        type: "donate",
        item: row
      };
    collection.push(index);
  }

  return collection;
}

function groupByZone(actions) {
  const groups = {};
  for (const action of actions) {
    if (!groups.hasOwnProperty(action.item.zone)) {
      groups[action.item.zone] = [];
    }

    groups[action.item.zone].push(action.type);
  }

  return groups;
}

function clonePantry(pantry) {
  const pantryCopy = [];
  for (const shelf of pantry) {
    pantryCopy.push(new Object({...shelf}));
  }
  return pantryCopy;
}

Expected behavior

I expected more clear instructions and failed test messages.

Screenshots

No response

System

  • Device: [Desktop]
  • OS: [Archlinux]
  • Browser: [Brave]
  • Version: [v1.19.128]

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    scope: curriculumLessons, Challenges, Projects and other Curricular Content in curriculum directory.status: waiting triageThis issue needs help from moderators and users to reproduce and confirm its validity and fix.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions