Ramda.js R.descendNatural() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Function

Definition

Builds a descending natural-sort comparator from a locale and a string getter. Part of Ramda Function since v0.30.1 (stable — not deprecated, experimental, or non-standard).

Note: Uses localeCompare with { numeric: true }, then reverses the order. The getter must return a string. Pair with R.sort.

Syntax

Call R.descendNatural. Start with this line.

Ramda
R.descendNatural(locales, fn)
CallWhat it does
R.descendNatural(locales, fn)Primary signature.
R.descendNatural(...)Call the function helper.

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

Library declarations
Ramda
R.descendNatural(locales, fn)

Parameters

ParameterDescription
localesRequired. BCP 47 tag(s), same idea as Intl.Collator
fnRequired. Unary function that returns a string

Return Value

Return ValueDescription
*Comparator: -1 / 0 / 1 for R.sort

Ramda Examples

Example 1 — Official English Reverse Natural Sort

Numbers inside strings sort as numbers, largest first.

Ramda
const unsorted = ['3', '1', '10', 'Ørjan', 'Bob', 'Älva'];

console.log(R.sort(R.descendNatural('en', R.identity), unsorted));
// → ['Ørjan', 'Bob', 'Älva', '10', '3', '1']
Try It Yourself

How It Works

  1. Getter. R.identity returns each string as-is.
  2. Numeric. localeCompare with numeric: true treats '10' as ten, then reverses → 10, 3, 1.
  3. Letters. English collation puts Ørjan near the end, so reverse order places it first; Bob before Älva.
  4. Immutable. R.sort returns a new array; unsorted is unchanged.

Example 2 — English vs Swedish

Same six strings; Ä moves because Swedish sorts Ä after Z.

Ramda
const unsorted = ['3', '1', '10', 'Ørjan', 'Bob', 'Älva'];

console.log(R.sort(R.descendNatural('en', R.identity), unsorted));
// → ['Ørjan', 'Bob', 'Älva', '10', '3', '1']

console.log(R.sort(R.descendNatural('sv', R.identity), unsorted));
// → ['Ørjan', 'Älva', 'Bob', '10', '3', '1']
Try It Yourself

How It Works

  1. Same numbers. Both locales keep 10, 3, 1 at the end.
  2. English names. Reverse order: Ørjan, Bob, Älva.
  3. Swedish names. Ä sorts after Z, so reverse order puts Älva before Bob.
  4. One change. Only the locale string differs — same getter and list.

Example 3 — R.descendNatural vs R.descend

Plain descending string compare puts '3' before '10'.

Ramda
const unsorted = ['3', '1', '10', 'Ørjan', 'Bob', 'Älva'];

console.log(R.sort(R.descendNatural('en', R.identity), unsorted));
// → ['Ørjan', 'Bob', 'Älva', '10', '3', '1']

console.log(R.sort(R.descend(R.identity), unsorted));
// → ['Ørjan', 'Älva', 'Bob', '3', '10', '1']
Try It Yourself

How It Works

  1. Natural. Digits compare as numbers → 10 before 3.
  2. Lexicographic. R.descend uses < / >; '3' > '1', so '3' before '10'.
  3. Names. Plain descend also follows raw Unicode, not a language alphabet.
  4. Rule. Human filename / version lists → natural; plain ages / scores → R.descend.

Example 4 — Filenames: file10 before file2

The everyday reason to pick reverse natural sort.

Ramda
const files = ['file10.txt', 'file2.txt', 'file3.txt'];

console.log(R.sort(R.descendNatural('en', R.identity), files));
// → ['file10.txt', 'file3.txt', 'file2.txt']
Try It Yourself

How It Works

  1. Read digits. Numeric collation sees 10, 3, and 2 inside the names.
  2. Reverse. Largest first → file10, then file3, then file2.
  3. Contrast. Plain R.descend would put file3 first because '3' > '1'.
  4. Use. File pickers, version labels, and track titles.

Example 5 — Sort Objects by a String Field

Pass R.prop('name') the same way R.descend uses R.prop('age').

Ramda
const items = [
  { name: 'file10.txt', size: 90 },
  { name: 'file2.txt', size: 10 },
  { name: 'file3.txt', size: 20 }
];

console.log(R.sort(R.descendNatural('en', R.prop('name')), items));
// → file10, file3, file2 (full objects)
Try It Yourself

How It Works

  1. Locale first. Still 'en' (or any BCP 47 tag).
  2. Getter second. R.prop('name') pulls the string field to compare.
  3. Payload rides along. Whole objects are reordered; size is not compared.
  4. Flip. For smallest-first filenames, use R.ascendNatural.

Browser & Runtime Support

R.descendNatural is a Ramda Function helper since v0.30.1. It runs anywhere Ramda runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install ramda. Collation uses the host localeCompare.

✓ Stable · Ramda 0.30.1+

R.descendNatural()

Available in [email protected]+ full builds. Works in evergreen browsers and current Node LTS when Ramda is installed. Numeric collation follows the JavaScript engine.

100% With Ramda 0.30.1+
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.descendNatural Ramda 0.30.1+

Bottom line: Safe for production once Ramda 0.30.1+ is loaded. Use a CDN build such as ramda.min.js in the browser, or install ramda from npm for Node. Very old engines may differ slightly on numeric collation.

Frequently Asked Questions

R.descendNatural(locales, fn) returns a descending comparator for R.sort. It compares fn(a) and fn(b) with String.prototype.localeCompare and { numeric: true }, so '10' comes before '3' and letters follow the given locale in reverse.

Next: R.empty()

Learn how to get a fresh empty array, string, or object of the same type.

R.empty() 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.

8 people found this page helpful