Rank a Leaderboard with Ties

Write the code, see it run, pass the checks.

The problem

  • medium
  • Code

The Leaderboard component gets a players prop: a list of { name, points } objects in no particular order (the preview uses Ada 120, Ben 95, Cleo 120, Dev 80, Eve 95 and Finn 60). Show them as list items, most points first, each reading like "1. Ada: 120 points" (always "points"). Players with equal points share a rank and keep their order from the prop, and the next rank skips the places they used, as in sports tables: 120, 120 and 95 are ranked 1, 1 and 3. Write the rank into the text yourself, since a numbered list's own numbers can't show ties. Don't change the array you were given: sort a copy.

Your code must pass

  • Sorts players by points, most first
  • Equal points share a rank and the next rank skips
  • Doesn't change the players prop
  • Updates when the players prop changes