Sort Functions
Overview of Ramda's sorting functions. (4 min. read)
We'll cover the following...
We'll cover the following...
Sort Functions
The native sort is destructive, meaning it mutates the array.
Ramda provides a non-destructive sort function.
sortBy applies a function to your values before comparing them. Sorting by absolute value, for example, is trivial now.
If you’d like to sort by multiple criteria, sortWith is your friend. This example sorts people by their age, then name.
Ramda’s ascend functions wraps around prop('age'), telling it “Sort by age, ascending (smallest first)”.
Same with prop('name'): “Sort by name, ascending (A, B, C, D…).”
So if they’re the same age, sortWith will then sort by name.
For the opposite effect, use descend.
Now people's sorted in opposite order.