Novicesyntax & basics
The Nightwatch Roster
The watch-captain of bitwick keeps the night roster on a slate by the gatehouse door: a line of watcher names in the order they take the wall. When a night passes, the name at the front of the line goes to the very back and every other name moves up one place.
Write nightWatch(names, nights).
namesis a list of strings, the roster in its current order.nightsis an integer, zero or greater, counting how many nights pass.
Return a list of strings: the roster after that many nights have passed.
nights may be larger than the number of names on the slate. If names is empty, return an empty list.
examples
- case 1
names of ["Ada", "Bram", "Cora", "Dell"], nights of 1["Bram", "Cora", "Dell", "Ada"] - case 2
names of ["Ada", "Bram", "Cora"], nights of 7["Bram", "Cora", "Ada"] — seven nights over three watchers lands in the same place as one night - case 3
names of [], nights of 5[] — an empty slate stays empty
- reward
- 130 XP
- signature
nightWatch
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
loading the editor…
- one night shifts by one
- zero nights leaves the slate alone
- more nights than watchers
- a full turn comes back around
- empty slate
- lone watcher
- partway through a long roster