Skip to content
dreamcode
dreamcode
Projects
Typed Inventory
Guided projectTypeScript
Reward: +220 XP
PROJECT BRIEF

Typed Inventory

The Item interface is written for you. Write restockReport(items, threshold) that returns a Report:

  • low: names of items whose quantity is below the threshold, sorted alphabetically
  • value: the total value of all stock (quantity times price), rounded to 2 decimal places

Keep the types: the function must accept Item[] and a number, and return Report.

Build it step by step
  1. Use filter to keep items with qty < threshold, then map to their names.
  2. Sort the names with .sort().
  3. Add up qty * price with reduce.
  4. Round with Math.round(total * 100) / 100.
Examples
restockReport([{ name: "rope", qty: 2, price: 4.5 }, { name: "lamp", qty: 10, price: 12 }, { name: "map", qty: 1, price: 3.25 }], 5)
{ low: ["map", "rope"], value: 132.25 }
restockReport([], 3)
{ low: [], value: 0 }
project.ts
TYPESCRIPT
Saved as you type

Tests

0 of 3 passing
  • two items running low
    restockReport([{ name: "rope", qty: 2, price: 4.5 }, { name: "lamp", qty: 10, price: 12 }, { name: "map", qty: 1, price: 3.25 }], 5)
    expected { low: ["map", "rope"], value: 132.25 }
  • empty shelf
    restockReport([], 3)
    expected { low: [], value: 0 }
  • prices that need rounding
    restockReport([{ name: "gum", qty: 3, price: 0.1 }], 1)
    expected { low: [], value: 0.3 }
On the line
+220 XP
Pass all 3 tests to claim it.