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
Filter and paginate public records without mutating the source.
- Search: keep a row when its title contains the query, ignoring case
(
"REACT"matches"react hooks"). Trim the query; a repeated query uses its first value; no query matches every row. - Pages: two matching rows per page. A page that isn't a whole number becomes 1, and a page past the end becomes the last page, as in the pagination lesson.
- Output: only
idandtitlefor each row, plus the page actually shown.
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
{"rows": [{"id": 1, "title": "React", "private": "x"}, {"id": 2, "title": "Forms"}, {"id": 3, "title": "React tests"}], "query": [" react ", "forms"], "page": "9"}→{"page": 1, "items": [{"id": 1, "title": "React"}, {"id": 3, "title": "React tests"}]}. - Input
{"rows": [{"id": 1, "title": "React"}, {"id": 2, "title": "react hooks"}, {"id": 3, "title": "Forms"}, {"id": 4, "title": "React tests"}], "query": "REACT", "page": "2"}→{"page": 2, "items": [{"id": 4, "title": "React tests"}]}.
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
Normalize the URL inputs first, calculate the matching list, then derive the bounded page and public output.
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.