‹ back to the board

Saturday, October 17

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).

  • sightings is a list of strings, ordered from oldest to newest. It may be empty, and the same place may appear more than once.
  • n is a non-negative integer.

Return a new list holding the last n entries of sightings, in the same order they appear in sightings.

  • If n is 0, return an empty list.
  • If n is greater than or equal to the length of sightings, return all of the entries.

Do not modify sightings.

  • slicing and indexing
  • Novice

examples

  1. case 1sightings of ["Ashwick Stump", "Heron Pool", "Black Alder", "Mossway"], n of 2["Black Alder", "Mossway"]
  2. case 2sightings of ["Ashwick Stump", "Heron Pool", "Black Alder"], n of 0[] — the guide asked for no sightings, so none are returned
  3. case 3sightings 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
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…
  • 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
The Last Lights of Pellbrook Fen · bitwick