The Bounty Schedule of Sarnwold Marches
The Warden of the Sarnwold Marches nails a bounty schedule to the board each season. It lists every beast of the fens the Warden will pay for, and how many silver pieces each trophy is worth. Hunters come back from the mists with sacks of trophies, and some of those trophies are from beasts the Warden never asked for.
Write bountyTotal(schedule, trophies).
scheduleis a dictionary (object) that maps a beast's name (a string) to the bounty paid for one trophy of that beast (a non-negative integer).trophiesis a list of strings. Each string is the name of the beast one trophy was taken from. The same name may appear more than once.
Return the total silver, as an integer, owed for all the trophies. Each trophy whose name is a key in schedule earns that key's value, once per appearance in the list. A trophy whose name is not a key in schedule earns 0. Names must match exactly, including capitalisation. If trophies is empty, return 0.
examples
- case 1
schedule of { "ghoul": 5, "barghest": 12, "marsh-imp": 2 }, trophies of ["ghoul", "ghoul", "barghest"]22 (5 + 5 + 12) - case 2
schedule of { "ghoul": 5, "barghest": 12 }, trophies of ["ghoul", "wyvern", "Ghoul"]5 ("wyvern" is not on the schedule, and "Ghoul" does not match "ghoul") - case 3
schedule of { "ghoul": 5 }, trophies of []0
- reward
- 140 XP
- signature
bountyTotal
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- repeated and mixed trophies
- no trophies brought
- unlisted beast earns nothing
- empty schedule
- capitalisation must match
- zero-value bounty
- single trophy
- long haul