Novicesyntax & basics
The Last Lights of Pellbrook Fen
Contract of the Lantern Company — posted at the Bitwick board
The Fen-Wardens of Pellbrook keep a record of every will-o'-wisp seen drifting over the black water. Each sighting is written down as the name of the place it was seen, in the order the sightings happened. The oldest is first and the newest is last. Before the Lantern Company wades into the fen at dusk, its guide wants only the freshest of these sightings.
Write lastSightings(sightings, n).
sightingsis a list of strings, ordered from oldest to newest. It may be empty, and the same place may appear more than once.nis a non-negative integer.
Return a new list holding the last n entries of sightings, in the same order they appear in sightings.
- If
nis0, return an empty list. - If
nis greater than or equal to the length ofsightings, return all of the entries.
Do not modify sightings.
examples
- case 1
sightings of ["Ashwick Stump", "Heron Pool", "Black Alder", "Mossway"], n of 2["Black Alder", "Mossway"] - case 2
sightings of ["Ashwick Stump", "Heron Pool", "Black Alder"], n of 0[] — the guide asked for no sightings, so none are returned - case 3
sightings of ["Heron Pool", "Mossway", "Gibbet Reed"], n of 6["Heron Pool", "Mossway", "Gibbet Reed"] — fewer than 6 exist, so all of them are returned
- reward
- 150 XP
- signature
lastSightings
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
loading the editor…
- last two of four
- n of zero gives empty
- n larger than record
- n equal to length
- empty record
- empty record and zero
- single sighting
- repeated places kept
- only the newest