Curriculum

Curriculum

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`.

Selected choicePick a choice below
Result—

Try it yourself

Compare how the promoter behaves on partial fills, zero seats, and empty waitlists.

Reveal the explanation
  1. waitlist = [Ana(T), Bo(F), Cem(T), Dara(T)], openSeats = 2

    ["Ana", "Cem"]. Skips ineligible Bo and stops once 2 seats are filled.

  2. waitlist = [Ana(T), Cem(T)], openSeats = 0

    [] (empty list). Zero open seats promotes nobody.

  3. 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.

Review first
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

Waitlist is `[Ana(eligible), Bo(ineligible), Cem(eligible)]` and `openSeats = 2`. What bug happens if you slice first and filter second?
Show the answer and reasoning

Correct answer You only inspect Ana and Bo, wrongly returning ["Ana"] and leaving Cem behind

Slicing before filtering wastes a seat slot on an ineligible entry; you must filter first (or count only promoted entries).