Problem statement
A leaderboard whose ordering is unreliable when two entrants share the same score. A sort with a documented tiebreak, a position number, and a highest-first / lowest-first toggle must together decide the standings from an in-memory array of entrants, using Vanilla TypeScript and standard DOM APIs.
Demo
The page, styles, mock data, panel markup, toggle button, and DOM rendering are already scaffolded and wired. Only the sortLeaderboard function in src/js/leaderboard.ts is missing — implement it so every test passes. Do not edit any other file.
What to implement
- Rank the entrants by score with the highest at the top by default.
- When two entrants have the same score, put the one with the earliest finish time first; when those are also equal, put the one whose name comes first in ascending order.
- Give each entrant a position number, and let entrants with the same score share the same position number; the next distinct score jumps ahead by the size of the tied group.
- Toggle the ranking between highest-first and lowest-first, and update the toggle's label to match the direction currently in effect.
- Show one row per entrant in the list container, holding that entrant's position, name, score, and finish time.
- Replace the previous rows on every render, so no stale rows remain behind.
- Produce the same standings every time the same entrants and direction are supplied.
- Leave the entrants you were given unchanged, and leave the panel, the toggle, and the rest of the page as you found them.
- Everything shown must come from the entrants you were given — nothing should be hardcoded.
