Command Palette

Search for a command to run...

Hectal
Phase 7: Shapes and the Chart Catalogue
Data Visualization · Exercise 4 of 4 Previous
Intermediate

Spread direct labels

Direct labels at the ends of lines can overlap. Write spread(ys, min): it takes label positions (in any order) and returns positions where neighbours are at least min apart, pushing labels down only.

Keep the original order of the list. spread([10, 12, 50], 13) must return [10, 23, 50]. Assign the function to window.spread.

What Check tests

  1. [10, 12, 50] becomes [10, 23, 50]
  2. The order of the list is kept
  3. An empty list gives an empty list
  4. A pushed label can push the next one

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.

Your page

Press Run to see the page.

Console

Nothing logged yet.