Ramda.js R.descend() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Function

Definition

R.descend(fn) builds a descending comparator from a getter fn. Pass it to R.sort so larger values come first (oldest, highest score, Z-to-A). Part of Ramda Function since v0.23.0 (stable — not deprecated).

Stable: Added in Ramda v0.23.0. Not deprecated, experimental, or non-standard. See also R.ascend and R.descendNatural.

Syntax

Call R.descend. Start with this line.

Ramda
R.descend(fn)
CallWhat it does
R.descend(fn)Primary signature.
R.descend(...)Call the function helper.

Prefer import { descend } from "ramda" when you want a named import.

Library declarations
Ramda
R.descend(fn)

Parameters

ParameterDescription
fnRequired. Unary getter; values compared with < / >

Return Value

Return ValueDescription
*Comparator (a, b) → -1 | 0 | 1

Ramda Examples

Example 1 — Official byAge Sort

Sort people oldest-first with R.descend and R.sort.

Ramda
const byAge = R.descend(R.prop("age"));
const people = [
  { name: "Emma", age: 70 },
  { name: "Peter", age: 78 },
  { name: "Mikhail", age: 62 }
];

console.log(R.sort(byAge, people));
// → [{ name: "Peter", age: 78 }, { name: "Emma", age: 70 }, { name: "Mikhail", age: 62 }]
Try It Yourself

How It Works

  1. Getter. R.prop("age") pulls the number to compare.
  2. Comparator. R.descend puts larger ages first.
  3. Sort. R.sort(byAge, people) returns a new array.
  4. Order. Peter (78), Emma (70), Mikhail (62).

Example 2 — Comparator Signs

See the -1 / 0 / 1 contract from the type docs.

Ramda
const byAge = R.descend(R.prop("age"));
const younger = { name: "Mikhail", age: 62 };
const older = { name: "Emma", age: 70 };

console.log(byAge(older, younger));
// → -1

console.log(byAge(younger, older));
// → 1

console.log(byAge(older, older));
// → 0
Try It Yourself

How It Works

  1. Larger first. fn(older) > fn(younger) → -1 (older before younger).
  2. Swap args. The opposite pair returns 1.
  3. Tie. Same ages → 0.
  4. Sort uses this. R.sort reorders until every pair agrees.

Example 3 — Sort Numbers Largest First

Use R.identity when the list items are already comparable.

Ramda
console.log(R.sort(R.descend(R.identity), [30, 4, 21]));
// → [30, 21, 4]
Try It Yourself

How It Works

  1. Getter. R.identity returns each number as-is.
  2. Descend. Larger numbers should come first.
  3. Sort. [30, 4, 21] becomes [30, 21, 4].
  4. Immutable. The input array is not mutated.

Example 4 — R.descend vs R.ascend

Same people list: oldest-first vs youngest-first.

Ramda
const people = [
  { name: "Emma", age: 70 },
  { name: "Peter", age: 78 },
  { name: "Mikhail", age: 62 }
];

console.log(R.sort(R.descend(R.prop("age")), people));
// → Peter, Emma, Mikhail

console.log(R.sort(R.ascend(R.prop("age")), people));
// → Mikhail, Emma, Peter
Try It Yourself

How It Works

  1. Same getter. Both use R.prop("age").
  2. Descend. Largest age first → Peter, Emma, Mikhail.
  3. Ascend. Smallest age first → Mikhail, Emma, Peter.
  4. Swap helper. Direction is the only change.

Example 5 — Sort by Name Z-to-A

Descend works for strings too (code-unit order).

Ramda
const byName = R.descend(R.prop("name"));
const people = [
  { name: "Emma", age: 70 },
  { name: "Peter", age: 78 },
  { name: "Mikhail", age: 62 }
];

console.log(R.sort(byName, people));
// → Peter, Mikhail, Emma
Try It Yourself

How It Works

  1. Getter. R.prop("name") compares strings.
  2. Z-to-A. Larger string first → Peter, then Mikhail, then Emma.
  3. Simple order. Uses < / >, not locale rules.
  4. Locales. For natural / locale sorts, use R.descendNatural.

Browser & Runtime Support

R.descend is a Ramda Function helper since v0.23.0. It runs anywhere Ramda runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install ramda.

✓ Stable · Ramda 0.23.0+

R.descend()

Available in [email protected] full builds once the library is loaded. Works in evergreen browsers and current Node LTS when Ramda is installed. No extra browser API is required.

100% With Ramda 0.23.0+
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
R.descend Ramda 0.23.0+

Bottom line: Safe for production once Ramda is loaded (CDN or npm). Prefer a modular build if you tree-shake. Pair with R.sort for immutable descending sorts.

Frequently Asked Questions

R.descend(fn) returns a comparator for R.sort. It compares fn(a) and fn(b) with < and > so larger values come first. The docs sample is const byAge = R.descend(R.prop('age')); then R.sort(byAge, people) lists Peter, Emma, then Mikhail.
const byAge = R.descend(R.prop('age')); R.sort(byAge, [{ name: 'Emma', age: 70 }, { name: 'Peter', age: 78 }, { name: 'Mikhail', age: 62 }]); //=> Peter (78), Emma (70), Mikhail (62). Added in v0.23.0. See also R.ascend, R.descendNatural, and R.ascendNatural.
The comparator returns -1 if fn(a) is greater than fn(b) (a should come first), 1 if fn(b) is greater than fn(a) (b should come first), and 0 if the compared values are equal.
R.ascend sorts smallest first (youngest, A-to-Z, lowest score). R.descend sorts largest first (oldest, Z-to-A, highest score). Swap one helper; keep the same getter such as R.prop('age').
No. R.sort(byAge, people) returns a new array. Native array.sort() mutates in place. Prefer R.sort with R.descend when you want an immutable sort.
No. R.descend is a stable Ramda function helper from v0.23.0. It is not deprecated, experimental, or non-standard.

Next: R.descendNatural()

Learn locale-aware descending sorts for natural string order.

R.descendNatural() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful