Sort Table Rows by a Typed Column

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

The problem

  • easy
  • Code

Write sortRows(rows, column, direction): return a new array of the rows sorted by their value in column, ascending for asc and descending for desc, leaving rows itself unchanged. Numbers compare as numbers and strings with localeCompare, and rows with equal values keep their order. Type it so column must be a key of the row type, direction can only be asc or desc, and the result keeps the rows' own type.

Your code must pass

  • Sorts by a column in either direction
  • Keeps equal rows in order and leaves rows unchanged
  • Has no type errors
  • Rejects a column the rows don't have
  • Only takes asc or desc
  • Returns the rows' type