StaffCoder
TypeScript
Vanilla TypeScriptTypeScript 7.0
6 modules · 24 challengesSign up
Module 6 · Arrays & Data Transformation

Leaderboard Sorting

easy—No data yet

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.

More in Arrays & Data Transformation

See the module
Group Bookings By DayReduce a bookings array into a map keyed by date, each entry holding its bookings sorted by start time and a count. Every day in the requested range is included — days with no bookings appear with an empty list — keys are returned in chronological order, and a booking outside the range is excluded.—No data yeteasyOrder TotalsCompute an order summary from an order-lines array using map, filter, and reduce: item count, subtotal, discount total, tax, and grand total, excluding cancelled lines from every figure. An empty order returns zeros — never NaN or null — and a line with zero quantity contributes nothing. The input array is never mutated.—No data yeteasyInventory Summary PanelTransform a stock array into a summary (total value, low-stock count, out-of-stock list, top categories by value) and render each part into the panel. Values render formatted, every derived figure comes from the transform rather than the DOM, and re-running with new data replaces the rendered summary rather than appending.—No data yeteasy

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.