‹ back to the board

Wednesday, September 9

Novicesyntax & basics

The Innkeeper's Key Rack

The inn at bitwick keeps a key rack by the stairs. Each hook is labelled with a room name, and beneath the hook the innkeeper chalks the name of whoever is sleeping there tonight. A room with no hook on the rack is not part of the inn at all.

You are given rooms, a dictionary whose keys are room names (strings) and whose values are the chalked guest names (strings). You are also given keys, a list of room names to look up, in order.

Write readRack(rooms, keys), which returns a new list of strings of the same length as keys. For each room name in keys, in order: if that name is a key of rooms, the result holds the value stored for it, exactly as given — including when that value is the empty string. If that name is not a key of rooms, the result holds the string "vacant".

rooms and keys may each be empty. A name may appear in keys more than once, and each occurrence produces its own entry.

  • dictionary and object access
  • Novice

examples

  1. case 1rooms of {"Oak": "Mira", "Ash": "", "Fen": "Doro"}, keys of ["Oak", "Ash", "Birch"]["Mira", "", "vacant"] — Ash has a hook, so its blank chalk is returned as the empty string; Birch has no hook at all
  2. case 2rooms of {} , keys of ["Oak", "Oak"]["vacant", "vacant"]
reward
120 XP
signature
readRack
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…
  • mixed rack with a blank chalk
  • no rooms asked for
  • empty rack
  • repeated lookups keep their order
  • single hook, single lookup
  • every hook blank
The Innkeeper's Key Rack · bitwick