Novicesyntax & basics
The Spirit-Totem of Ulgrath Fells
High on Ulgrath Fells, the clans keep a spirit-totem of carved figures. Each new figure is set on top of the last, so the totem grows upward, one carving at a time. Before the winter rite, the Shamans' Circle posts a bounty for a reading of the uppermost figures, spoken from the top down.
Write readTotem(carvings, k).
carvingsis a list of strings. Each string names one figure, listed from the bottom of the totem (first element) to the top (last element).kis a non-negative integer.
Return a list of strings with the top k figures, ordered from the topmost figure first downward.
- If
kis greater than or equal to the number of figures, return every figure, still topmost first. - If
kis 0, orcarvingsis empty, return an empty list.
examples
- case 1
carvings of ["Bear", "Elk", "Raven", "Owl"] (bottom to top), k of 2["Owl", "Raven"] - case 2
carvings of ["Bear", "Elk", "Raven", "Owl"], k of 6["Owl", "Raven", "Elk", "Bear"] (more asked for than exist, so all four, topmost first) - case 3
carvings of ["Bear", "Elk", "Raven", "Owl"], k of 0[] (nothing is read)
- reward
- 140 XP
- signature
readTotem
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
loading the editor…
- top two of four
- k equals length
- k exceeds length
- k is zero
- empty totem
- single figure
- top three of five
- top one of five