Summarise Sales in a Pivot Table
Write the code, see it run, pass the checks.
The problem
- medium
- Code
The Pivot component gets a sales prop: a list of { region, quarter, amount } objects, where amount is a whole number. Summarise it in a real table (table, tr, th and td elements). The first row is the header: "Region", then each quarter in the order it first appears in the sales, then "Total". Then one row per region, in the order each first appears: the region's name, its summed amount for each quarter (0 where it has none), and its total. The last row starts with "Total" and holds each quarter's total and the grand total. Every cell holds just its text or number. A button "Swap rows and columns" turns the table round: the header then starts with "Quarter" and lists the regions, with one row per quarter, and clicking it again turns it back. With no sales, the table is just the header "Region" and "Total" and a "Total" row of 0.
Your code must pass
- Sums each region's sales per quarter, with row and column totals
- Works the rows and columns out from the sales it's given
- Swap rows and columns puts quarters down the side
- Swapping again turns it back
- With no sales it shows a Total of 0