Command Palette

Search for a command to run...

Hectal
Phase 17: Storytelling and Scrollytelling
Data Visualization · Exercise 3 of 6 PreviousNext
Intermediate

Which step is in the middle?

closestStep(centres, mid) gets the vertical centre of each step and the middle of the screen, and returns the index of the nearest step. It returns the first step's index whatever the numbers.

Return the index of the centre nearest mid (the lowest index on a tie) and -1 for an empty list.

What Check tests

  1. Picks the nearest centre
  2. An empty list gives -1
  3. A tie keeps the lower index

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Console

Nothing printed yet.