StaffCoder
TypeScript
Vanilla TypeScriptTypeScript 7.0
6 modules · 24 challengesSign up
Module 6 · Arrays & Data Transformation

Inventory Summary Panel

easy—No data yet

Problem statement

A stock panel with raw rows and no sense of what needs attention. A single transform must turn the stock array into a summary — total value, low-stock count, out-of-stock list, and top categories by value — so the panel can show what matters, and re-running with new data must replace the rendered summary rather than adding to it, using Vanilla TypeScript and standard DOM APIs.

Demo

The page, styles, mock stock data, panel markup, reshuffle button, and DOM rendering are already scaffolded and wired. Only the summarize function in src/js/summary.ts is missing — implement it so every test passes. Do not edit any other file.

What to implement

  • Add up the value of every item to get the total value of the stock, where an item's value is its quantity times its price.
  • Count the items that still have stock but are at or below the given threshold.
  • Collect the items whose quantity is exactly zero and put them in alphabetical order by name.
  • For each category that appears in the stock, add up the value of the items in that category, then keep the three highest categories by value, breaking ties by category name in alphabetical order.
  • Return one summary object with the total value, the low-stock count, the out-of-stock list, and the top categories, so the panel can read every figure from that one object.
  • Leave the stock array you were given unchanged.
  • Everything shown must come from the stock you were given — nothing should be hardcoded.

More in Arrays & Data Transformation

See the module
Group Bookings By DayReduce a bookings array into a map keyed by date, each entry holding its bookings sorted by start time and a count. Every day in the requested range is included — days with no bookings appear with an empty list — keys are returned in chronological order, and a booking outside the range is excluded.—No data yeteasyLeaderboard SortingSort leaderboard entries by score descending with a documented tiebreak (earlier finish time, then name) without mutating the input. Support an ascending toggle and return a position for each entry, sharing a position number across genuine ties. The order is stable across repeated calls.—No data yeteasyOrder TotalsCompute an order summary from an order-lines array using map, filter, and reduce: item count, subtotal, discount total, tax, and grand total, excluding cancelled lines from every figure. An empty order returns zeros — never NaN or null — and a line with zero quantity contributes nothing. The input array is never mutated.—No data yeteasy

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.