‹ back to the board

Wednesday, September 23

Novicesyntax & basics

The Cellar Ledger of the Sleeping Badger

The cellarer of the Sleeping Badger keeps one ledger of what rests in the cellar, and each morning a runner brings down a list of what the taproom wants.

The ledger is given as stock: a mapping from cask name (a string) to the number of casks held (a non-negative integer). The morning list is given as order: a list of cask names (strings), which may repeat and may name casks the ledger has never heard of.

Write tallyOrder(stock, order), which returns a list of integers of the same length as order. The entry at each position is the number the ledger records for the cask named at that position in order, or 0 if that name does not appear in the ledger at all. The order of the returned list matches the order of order.

  • dictionary and object access
  • Novice

examples

  1. case 1stock of {"mead": 7, "cider": 0}, order of ["mead", "brandy", "cider"][7, 0, 0] — brandy is not in the ledger, and cider is in the ledger at zero; both report 0
  2. case 2stock of {"mead": 7}, order of ["mead", "mead"][7, 7] — each request gets its own entry
  3. case 3stock of {"mead": 7}, order of [][] — nothing was asked for
reward
130 XP
signature
tallyOrder
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…
  • a plain morning order
  • a cask the ledger never heard of
  • recorded at zero reads the same as absent
  • the same cask asked for twice
  • an empty morning list
  • an empty ledger
  • a single cask, well stocked
The Cellar Ledger of the Sleeping Badger · bitwick