Build a Workshop Waitlist Promoter
Scenario
Contract `promoteWaitlist(waitlist, openSeats)`: each entry has `{ name, eligible }`. `openSeats` must be integer >= 0 (else `INVALID_WAITLIST_INPUT`). Return the names of the first `openSeats` entries where `eligible === true`.
Try it yourself
Compare how the promoter behaves on partial fills, zero seats, and empty waitlists.
| Case | Result |
|---|---|
| waitlist = [Ana(T), Bo(F), Cem(T), Dara(T)], openSeats = 2 | Select a choice above to see what happens. |
| waitlist = [Ana(T), Cem(T)], openSeats = 0 | Select a choice above to see what happens. |
| waitlist = [Ana(T)], openSeats = 3 | Select a choice above to see what happens. |
Reveal the explanation
- waitlist = [Ana(T), Bo(F), Cem(T), Dara(T)], openSeats = 2
["Ana", "Cem"]. Skips ineligible Bo and stops once 2 seats are filled.
- waitlist = [Ana(T), Cem(T)], openSeats = 0
[] (empty list). Zero open seats promotes nobody.
- waitlist = [Ana(T)], openSeats = 3
["Ana"]. Promotes all available eligible students without padding.
Using a fresh result list with an early stop (`result.length === openSeats`) keeps the function pure, preserves fairness order, and handles empty lists cleanly.
Download shared test cases
Your turn
Implement `promoteWaitlist` and run all cases in `fixture-waitlist-promoter`, asserting the input array is not mutated.
Common mistake Slicing the first `openSeats` entries BEFORE filtering out ineligible students.
Check your work
Passing test suite proving `[Ana(T), Bo(F), Cem(T)]` with `openSeats = 2` returns `["Ana", "Cem"]`, not `["Ana"]`.
Project brief
- Basic
- Filter eligible entries in order and return up to `openSeats` names.
- Intermediate
- Validate `openSeats >= 0` and array input (`INVALID_WAITLIST_INPUT`) plus verify empty waitlist returns `[]`.
- Stretch
- Return both `{ promoted, remaining }` without mutating the original waitlist.
What to hand in
Include your diagram, expected-result table, code, actual test output, and the commit or diff you reviewed.
Review criteria
- Logic · Your diagram shows every required path and boundary.
- Verification · The tests exercise the stated acceptance cases and the recorded results match the code.
- Review · The change is focused and you can explain the decision it implements.
Quick check
This browser could not save your progress. Changes last until you leave the page.