The Night Watch Roster
The inn at bitwick keeps the night watch roster on a slate by the door: the watchers' names, written in the order they take the wall.
Each dawn the slate is rewritten so that a different name stands first, and everyone else follows in the same cyclic order as before. No name is added, dropped, or repeated — only the starting point moves.
Write watchOrder(watch, k).
watchis a list of strings, the names in their current order.kis an integer, zero or greater: how many places the start of the roster moves forward.
Return a new list of strings containing exactly the same names, beginning with the name at position k and continuing in order, wrapping back to the front of the list when the end is passed. If k is greater than or equal to the number of names, it continues to wrap around (so a k equal to the length gives back the original order). If watch is empty, return an empty list.
Do not modify the list you were given.
examples
- case 1
watch of ["Ada", "Bram", "Cleo", "Dag"], k of 1["Bram", "Cleo", "Dag", "Ada"] - case 2
watch of ["Ada", "Bram", "Cleo", "Dag"], k of 6["Cleo", "Dag", "Ada", "Bram"] — 6 wraps twice around the four names - case 3
watch of [], k of 3[]
- reward
- 130 XP
- signature
watchOrder
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- shifts by one
- zero leaves the order alone
- a full turn returns to the start
- wraps more than once
- empty slate
- a lone watcher
- last name first