‹ back to the board

Saturday, September 26

Novicesyntax & basics

The Roster of the Night Watch

A notice from the captain of the gate at bitwick.

The night watch roster is a list of watchmen's names, written in the order they stand their turns. When a watchman sends word that he cannot come, the captain crosses off the first entry bearing his name and leaves the rest of the roster exactly as it was — later entries with the same name still stand their turns.

Write crossOff(watch, absent).

  • watch is a list of strings, the roster in order. It may be empty.
  • absent is a single string, the name to cross off. Names are matched exactly, letter for letter, including capitalisation.

Return a new list of strings: the roster in its original order with the first entry equal to absent removed. If no entry matches absent, return a list with the same names in the same order.

  • list and array basics
  • Novice

examples

  1. case 1watch of ["Bran", "Cass", "Bran", "Dov"], absent of "Bran"["Cass", "Bran", "Dov"] — only the first Bran is crossed off
  2. case 2watch of ["Bran", "Cass"], absent of "Dov"["Bran", "Cass"] — nobody on the roster bears that name
  3. case 3watch of ["bran", "Bran"], absent of "Bran"["bran"] — the lowercase entry is a different name
reward
120 XP
signature
crossOff
not yet run

TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.

loading the editor…
  • removes only the first of two matches
  • name not on the roster
  • empty roster
  • single watchman crossed off
  • matching is case sensitive
  • match sits at the end
The Roster of the Night Watch · bitwick