Ramda.js R.ascendNatural() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Function

Definition

Makes an ascending comparator from a string getter using natural sorting via localeCompare (official Ramda docs). Digits compare as numbers (file2 before file10), and letters follow a BCP 47 locale such as 'en' or 'sv'. Pair it with R.sort.

Stable since v0.30.1: R.ascendNatural is a core Ramda helper — not deprecated, experimental, or non-standard. Prefer R.ascend for numbers or plain < / > comparison.

Syntax

Call R.ascendNatural. Start with this line.

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

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

Library declarations
Ramda
R.ascendNatural(locales, fn)

Parameters

ParameterDescription
localesRequired. BCP 47 tag(s) for Intl.Collator / localeCompare
fnRequired. Unary getter; must return a string

Return Value

Return ValueDescription
*Comparator (a, b) → Number (−1, 0, or 1)

Ramda Examples

Example 1 — Official English Natural Sort

Numbers and names in human order — the sample from the Ramda docs.

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

console.log(R.sort(R.ascendNatural('en', R.identity), unsorted));
Try It Yourself

How It Works

  1. Locale + getter. 'en' sets English collation; R.identity compares each string as-is.
  2. Numeric digits. localeCompare with numeric: true puts '1', '3', then '10'.
  3. Letter order. English places Ä before B, then Ørjan.
  4. Immutable. R.sort returns a new array; unsorted is unchanged.

Example 2 — English vs Swedish

Same list, different letter order — only the locale changes.

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

console.log(R.sort(R.ascendNatural('en', R.identity), unsorted));
console.log(R.sort(R.ascendNatural('sv', R.identity), unsorted));
Try It Yourself

How It Works

  1. Shared numbers. Both locales keep 1, 3, 10 first.
  2. English names. Älva → Bob → Ørjan.
  3. Swedish names. Bob first; Ä and Ø sort later in Swedish alphabet rules.
  4. Pick the user’s locale. Natural sort is not one global alphabet.

Example 3 — R.ascendNatural vs R.ascend

See the classic '10' before '3' trap with lexicographic sort.

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

console.log(R.sort(R.ascendNatural('en', R.identity), unsorted));
console.log(R.sort(R.ascend(R.identity), unsorted));
Try It Yourself

How It Works

  1. Natural. Digits compare as numbers → 1, 3, 10.
  2. Lexicographic. R.ascend uses < → '10' before '3'.
  3. Names differ too. Plain < does not apply locale letter rules.
  4. Rule of thumb. Filenames / typed digits in strings → natural; numbers → R.ascend.

Example 4 — Filenames: file2 before file10

The classic natural-sort demo for file pickers and version labels.

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

console.log(R.sort(R.ascendNatural('en', R.identity), files));
Try It Yourself

How It Works

  1. Embedded numbers. Collation reads 2, 3, and 10 as numbers inside the name.
  2. Human order. Result is file2, file3, file10.
  3. Lexicographic trap. Plain R.ascend would put file10 first.
  4. Reuse. Keep one named comparator for every file list in the app.

Example 5 — Sort Objects by a String Field

Pass R.prop('name') when records hold the sortable string.

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

console.log(R.sort(R.ascendNatural('en', R.prop('name')), items));
Try It Yourself

How It Works

  1. Field getter. R.prop('name') must return a string for each item.
  2. Same natural rule. Objects reorder like the filename list.
  3. Other fields untouched. size rides along with each object.
  4. Opposite direction. Use R.descendNatural for largest-first names.

Browser & Runtime Support

R.ascendNatural() needs Ramda 0.30.1+ and a runtime with String.prototype.localeCompare (all modern browsers and current Node). It is ordinary JavaScript once Ramda is loaded.

✓ Ramda 0.30.1+ · localeCompare

Ramda.js R.ascendNatural()

Works wherever you can load Ramda 0.30.1+ and Intl / localeCompare is available. Very old engines without localeCompare need a polyfill; there is no separate IE-only API for this helper.

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.ascendNatural() Universal*

Bottom line: Safe in projects on Ramda 0.30.1 or later. Load ramda.min.js from a CDN in the browser, or npm install ramda for Node, Bun, and Deno. Exact letter order depends on the engine’s Intl data for the chosen locale.

Frequently Asked Questions

R.ascendNatural(locales, fn) returns a comparator for R.sort. It compares fn(a) and fn(b) with String.prototype.localeCompare and { numeric: true }, so '10' comes after '3' and letters follow the given locale. Pair it with R.sort.

Next: R.binary()

Wrap any function so it ignores extra arguments beyond the first two.

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

12 people found this page helpful