Results table with toggleable column sorting and DNF times
A running club publishes the results of its Harbor 10 Mile race as a table. Runners want to find themselves by name, by age group, or by finishing position. Build the results table with sortable columns: clicking a column header sorts the rows by that column, and clicking it again reverses the order.
The starter code includes the results (in bib order) and the column config:
const RESULTS = [
{ bib: 101, runner: 'Priya Nair', age: 34, seconds: 5025 },
{ bib: 102, runner: 'Tom Becker', age: 41, seconds: null },
{ bib: 103, runner: 'Émile Roux', age: 29, seconds: 4710 },
// ... 5 more, up to bib 108
];
const COLUMNS = [
{ key: 'bib', label: 'Bib', sortable: false },
{ key: 'runner', label: 'Runner', sortable: true },
{ key: 'age', label: 'Age', sortable: true },
{ key: 'seconds', label: 'Finish time', sortable: true },
];
seconds is the runner’s finish time in seconds, or null if they did not finish.
COLUMNS, in order, and one row per runner. At first, show the rows in the order of RESULTS (bib order).h:mm:ss (5025 → 1:23:45, 4410 → 1:13:30), or DNF when seconds is null.localeCompare, and Age and Finish time as numbers.<th>) of the current sort column has aria-sort="ascending" or aria-sort="descending". Other sortable header cells have aria-sort="none". Before the first click, no header is ascending or descending.aria-hidden="true", since aria-sort already announces the direction.Initial (bib order): Priya Nair, Tom Becker, Émile Roux, Ana Silva, Kenji Ito, Dara Okafor, Felix Wong, Bea Larsen
Click Age: Émile Roux (29, bib 103), Dara Okafor (29, bib 106), Priya Nair (34, bib 101), Ana Silva (34, bib 104), ...
Click Age again: Kenji Ito (52), Felix Wong (45), Tom Becker (41, bib 102), Bea Larsen (41, bib 108), ...
Click Finish time: Felix Wong 1:13:30, Émile Roux 1:18:30, Bea Larsen 1:23:00, Priya Nair 1:23:45, Ana Silva 1:23:45,
Kenji Ito 1:33:10, Tom Becker DNF, Dara Okafor DNF
Click Finish time: Kenji Ito, Priya Nair, Ana Silva, Bea Larsen, Émile Roux, Felix Wong, Tom Becker DNF, Dara Okafor DNF
'Émile' < 'Felix' is false with plain string comparison, because É has a higher code point than any ASCII letter. localeCompare sorts it next to the other E names.Array.prototype.sort mutates its array.The tests click your headers and read the screen like a user would. You don’t need test ids, specific class names, or an exact HTML structure. They check that:
DNF.aria-sort="ascending" or aria-sort="descending" after a click, and it is (or contains) the clicked header.Capitalization and extra spacing don’t matter.