Novicesyntax & basics
The Bog-Bounties of Gorsemere
The Reed Wardens of Gorsemere Marsh pay coin for every beast hunted out of their bogs. Their bounty list maps each beast's name to the coins paid for one trophy of it. A hunter returns with a sack of trophies, one name per trophy, and the Wardens pay out the total.
Write tallyBounty(bounties, trophies), which returns the total coins owed.
bountiesis a dictionary (object) mapping a beast's name (a string) to a non-negative integer number of coins.trophiesis a list of strings, one per trophy brought in. The same name may appear more than once, and each occurrence is paid separately.- A trophy whose name is not a key in
bountiesis worth 0 coins. Names must match a key exactly, including capital letters. - Return the total as an integer. If
trophiesis empty, return 0.
examples
- case 1
bounties of { "mire toad": 3, "bog lurker": 40, "wisp": 12 }, trophies of ["mire toad", "wisp", "mire toad"]18 (3 + 12 + 3) - case 2
bounties of { "mire toad": 3, "bog lurker": 40, "wisp": 12 }, trophies of ["bog lurker", "swamp cat"]40 (the swamp cat is not on the list, so it pays nothing) - case 3
bounties of { "wisp": 12 }, trophies of ["Wisp"]0 ("Wisp" does not exactly match "wisp")
- reward
- 130 XP
- signature
tallyBounty
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
loading the editor…
- repeated trophies are each paid
- unlisted beast pays nothing
- empty sack
- empty bounty list
- names are case sensitive
- zero-coin bounty
- single trophy