Challenge: Reverse Sort
Try to sort in reverse order in a react app.
We'll cover the following
Task
The sort feature works, but the ordering only includes one direction. Implement a reverse sort when the button is clicked twice, so it becomes a toggle between normal (ascending) and reverse (descending) sort.
Optional Hints:
- Consider that reverse or normal sort could be just another state (e.g.
isReverse
) next to thesortKey
. - Set the new state in the
handleSort
handler based on the previous sort. - Use the new
isReverse
state for sorting the list with the sort function from the dictionary with the optionally appliedreverse()
function from JavaScript arrays.
Get hands-on with 1400+ tech skills courses.