Returns a new table with the rows sorted by the specified column.
sortedBy(column, sortFn)
column
The name or index of the column to sort by.
sortFn
A function that compares two values and returns a number less than 0 if the first value should come before the second, 0 if the values are equal, or a number greater than 0 if the first value should come after the second. If not specified, the default sort function is used.
The default sort function tries to detect whether the values in the column are numbers or strings and sorts them accordingly. If the values are numbers, they are sorted numerically. If the values are strings, they are sorted lexicographically.
new Table(["Item", "Count"], [
["Bicycle", 5],
["Scooter", 2]
]).sortedBy("Count")
| Item | Count |
|---|---|
| Scooter | 2 |
| Bicycle | 5 |