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
- Picks the nearest centre
- An empty list gives -1
- 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.
Press Run to see the page.
Console
Nothing printed yet.