Sort a Table by Column

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

The problem

  • medium
  • Code
  • Pro

A table lists four books and the year each came out. The column headers hold buttons labelled exactly "Title" and "Year". Clicking one sorts the rows by that column, lowest first; clicking the same one again reverses it. Until a header is clicked the rows keep their starting order. Give the sorted column's header cell (th) aria-sort="ascending" or "descending", and leave it off the other.

Your code must pass

  • Rows start in their original order
  • Clicking Title sorts by title, A to Z
  • Clicking Year again reverses the order
  • The sorted header has aria-sort