‹ back to the board

Sunday, September 27

Novicesyntax & basics

The Cellar Ledger of the Rusty Tankard

The cellarer of the Rusty Tankard keeps a ledger of what sits in the cellar: each barrel name written beside the number of measures left in it. Barrels that have been drained are not always struck out — some still sit in the ledger with a nought beside them — and casks the inn has never carried are simply absent.

Each morning the cook hands over a list of names to check before the market opens.

Write outOfStock(stock, wanted), where:

  • stock is a dictionary (object) whose keys are barrel names (strings) and whose values are the measures remaining (non-negative integers).
  • wanted is a list (array) of barrel names (strings). It contains no repeated names, and may be empty.

Return a new list of the names from wanted that the inn cannot serve: a name counts as unservable if it does not appear as a key in stock, or if it appears with a value of 0. The returned names must be in the same order as they appear in wanted. If every wanted name is servable, return an empty list.

  • dictionary and object access
  • Novice

examples

  1. case 1stock of {"ale": 3, "mead": 0, "cider": 7}, wanted of ["ale", "mead", "perry"]["mead", "perry"] — mead is written down but drained, perry was never in the ledger at all
  2. case 2stock of {"ale": 3, "cider": 7}, wanted of [][] — nothing was asked about, so nothing is reported
reward
120 XP
signature
outOfStock
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…
  • drained barrel and unknown barrel
  • empty wanted list
  • empty ledger
  • everything servable
  • order follows the wanted list
  • single name still in stock
The Cellar Ledger of the Rusty Tankard · bitwick