Example 1 — Official byAge Sort
Youngest first — the sample from the Ramda docs.
const byAge = R.ascend(R.prop('age'));
const people = [
{ name: 'Emma', age: 70 },
{ name: 'Peter', age: 78 },
{ name: 'Mikhail', age: 62 }
];
console.log(R.sort(byAge, people)); How It Works
- Pick the field.
R.prop('age')reads each person’s age. - Wrap with
R.ascend. That getter becomes a-1 / 0 / 1function namedbyAge. - Sort immutably.
R.sort(byAge, people)returns Mikhail (62), Emma (70), Peter (78). - Source stays intact.
peopleis unchanged — only the returned array is ordered.
