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
- [10, 12, 50] becomes [10, 23, 50]
- The order of the list is kept
- An empty list gives an empty list
- 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.