Close the four earlier lessons and work from this brief. The workspace has
an executable case table but an unfinished run function. Complete the rule
before looking at the solution. Twenty-four minutes is a suggested first pass;
split the work across sessions if you need more time.
The brief
Build a visible list from confirmed rows plus a pending row unless its id is already confirmed. Return savedCount from confirmed rows only. Never mutate either input.
Keep the function deterministic and leave its inputs unchanged. Explain how this rule connects to a Next.js page, action or route handler; the table is a contract harness, not a substitute for testing that transport.
Acceptance cases
- Input
{"saved": [{"id": 1, "title": "Routing"}], "pending": {"id": 2, "title": "Forms"}}→{"items": [{"id": 1, "title": "Routing"}, {"id": 2, "title": "Forms", "saving": true}], "savedCount": 1}.
Add one case of your own to examples: the least convenient input you can
think of, such as an empty list, a missing field or a repeated value. Work out
its expected result before you run it. The table's Input kept column must
say yes on every row: the rule may not change what it was given.
npm install and npm run dev. Hint 1: the idea
Separate validation, calculation and output shaping. Decide the failure precedence before writing the happy path.
Hint 2: a first step
A temporary item belongs in the displayed list, not the saved count. Use the record id to avoid a duplicate confirmation.
Show one solution
npm install and npm run dev. A matching output alone is not the whole check: the Input kept column must say yes too. Then explain the rule to yourself without reading the implementation.
Before the next day
- Which layer owns this decision, and which layer translates it for the reader?
- What happens on the least convenient input, not only the happy path?
- What would you test in a real browser or server that this pure function cannot establish?
Completion is saved in this browser only. It does not measure mastery.