‹ back to the board

Wednesday, October 21

Novicesyntax & basics

The Trophy-Ledger of Sennoway Keep

The Castellan of Sennoway Keep has posted a standing bounty on the beasts that prowl the hills below her walls. Hunters return with trophies, and the Keep's paymaster pays each trophy according to the bounty ledger. Your task is to work out how much a hunter is owed.

Write bountyPayout(bounties, trophies).

  • bounties is a dictionary (object) that maps a beast's name (a string) to the reward for one trophy of that beast (a non-negative integer number of coins).
  • trophies is a list of strings, one beast name per trophy the hunter brings in. The same name may appear more than once, and each occurrence is paid separately.

A trophy whose name is not a key in bounties pays 0 coins. Names must match a key exactly, and matching is case-sensitive, so "Stone-Troll" does not match "stone-troll".

Return the total number of coins owed for all the trophies, as an integer. If trophies is empty, return 0.

  • dictionary and object access
  • Novice

examples

  1. case 1bounties of {"barrow-hound": 5, "marsh-imp": 2, "stone-troll": 20}, trophies of ["marsh-imp", "barrow-hound", "marsh-imp"]9 (2 + 5 + 2)
  2. case 2bounties of {"barrow-hound": 5, "stone-troll": 20}, trophies of ["gloom-bat", "stone-troll"]20 (the gloom-bat is not in the ledger, so it pays 0)
  3. case 3bounties of {"barrow-hound": 5}, trophies of []0
reward
130 XP
signature
bountyPayout
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…
  • repeated trophies each pay
  • empty trophy list pays nothing
  • unlisted beast pays zero
  • empty ledger pays nothing
  • names are case-sensitive
  • a listed bounty of zero
  • single trophy
The Trophy-Ledger of Sennoway Keep · bitwick