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).
watchis a list of strings, the roster in order. It may be empty.absentis 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.
examples
- case 1
watch of ["Bran", "Cass", "Bran", "Dov"], absent of "Bran"["Cass", "Bran", "Dov"] — only the first Bran is crossed off - case 2
watch of ["Bran", "Cass"], absent of "Dov"["Bran", "Cass"] — nobody on the roster bears that name - case 3
watch of ["bran", "Bran"], absent of "Bran"["bran"] — the lowercase entry is a different name
- reward
- 120 XP
- signature
crossOff
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