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:
stockis a dictionary (object) whose keys are barrel names (strings) and whose values are the measures remaining (non-negative integers).wantedis 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.
examples
- case 1
stock 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 - case 2
stock of {"ale": 3, "cider": 7}, wanted of [][] — nothing was asked about, so nothing is reported
- reward
- 120 XP
- signature
outOfStock
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- drained barrel and unknown barrel
- empty wanted list
- empty ledger
- everything servable
- order follows the wanted list
- single name still in stock