Ramda.js R.ascend() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Function

Definition

Makes an ascending comparator function out of a function that returns a value that can be compared with < and > (official Ramda docs). Pass a getter such as R.prop('age'); Ramda returns -1, 0, or 1 for R.sort.

Stable since v0.23.0: R.ascend is a core Ramda helper — not deprecated, experimental, or non-standard. Prefer R.comparator when you need a custom less-than predicate instead of a getter.

Syntax

Call R.ascend. Start with this line.

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

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

Library declarations
Ramda
R.ascend(fn)

Parameters

ParameterDescription
fnRequired. Unary getter; return value must support < / >

Return Value

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

Ramda Examples

Example 1 — Official byAge Sort

Youngest first — the sample from the Ramda docs.

Ramda
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));
Try It Yourself

How It Works

  1. Pick the field. R.prop('age') reads each person’s age.
  2. Wrap with R.ascend. That getter becomes a -1 / 0 / 1 function named byAge.
  3. Sort immutably. R.sort(byAge, people) returns Mikhail (62), Emma (70), Peter (78).
  4. Source stays intact. people is unchanged — only the returned array is ordered.

Example 2 — Comparator Signs

Call the comparator on pairs without sorting the whole list.

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

console.log(byAge(younger, older)); // -1
console.log(byAge(older, younger)); // 1
console.log(byAge(older, older));   // 0
Try It Yourself

How It Works

  1. Younger first. 62 < 70 → -1 (a comes before b).
  2. Swap the pair. Now 70 < 62 is false and the reverse is true → 1.
  3. Equal ages. Neither value is smaller → 0 (tie).
  4. Contract complete. Those three numbers are all R.sort needs.

Example 3 — Sort Numbers Smallest First

When the list holds comparable values, use R.identity as the getter.

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

How It Works

  1. Identity getter. R.identity returns each number as-is.
  2. Avoid default string sort. Native [30, 4, 21].sort() would put 21 before 4.
  3. Numeric order. R.sort(R.ascend(R.identity), …) yields [4, 21, 30].
  4. Reuse the helper. Name it once and pass it to any list of numbers.

Example 4 — R.ascend vs R.descend

Same people, opposite order — swap one helper.

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

console.log(R.sort(R.ascend(R.prop('age')), people));
console.log(R.sort(R.descend(R.prop('age')), people));
Try It Yourself

How It Works

  1. Ascending. R.ascend puts smaller ages first → Mikhail … Peter.
  2. Descending. R.descend puts larger ages first → Peter … Mikhail.
  3. Same getter. Both use R.prop('age') — only the direction changes.
  4. Rule of thumb. Youngest / A-to-Z / lowest → ascend; opposite → descend.

Example 5 — Sort by Name A-to-Z

Any comparable field works — switch age for name.

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

console.log(R.sort(byName, people));
Try It Yourself

How It Works

  1. Change the key. R.prop('name') reads the string field instead of age.
  2. String comparison. < / > order names alphabetically.
  3. Result. Emma, Mikhail, Peter — A-to-Z.
  4. Natural order. For “file2 before file10”, see R.ascendNatural.

Browser & Runtime Support

R.ascend() is ordinary JavaScript once Ramda is loaded. It needs no special browser API — only a JS runtime that can run Ramda (v0.23.0+).

✓ Ramda 0.23.0+ · Any JS runtime

Ramda.js R.ascend()

Works in every modern browser and runtime where you can load Ramda (CDN or npm). Internet Explorer needs a build that targets that environment; there is no native IE API to polyfill.

100% With Ramda loaded
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.ascend() Universal

Bottom line: Safe in any project that includes Ramda 0.23.0 or later. Load ramda.min.js from a CDN in the browser, or npm install ramda for Node, Bun, and Deno.

Frequently Asked Questions

R.ascend(fn) returns a comparator for R.sort. It compares fn(a) and fn(b) with < and > so smaller values come first. The docs sample is const byAge = R.ascend(R.prop('age')); then R.sort(byAge, people) lists Mikhail, Emma, then Peter.
const byAge = R.ascend(R.prop('age')); R.sort(byAge, [{ name: 'Emma', age: 70 }, { name: 'Peter', age: 78 }, { name: 'Mikhail', age: 62 }]); //=> Mikhail (62), Emma (70), Peter (78). Added in v0.23.0. See also R.descend, R.ascendNatural, and R.descendNatural.
The comparator returns -1 if fn(a) is less than fn(b) (a should come first), 1 if fn(b) is less 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.ascend when you want an immutable sort.
No. R.ascend is a stable Ramda function helper from v0.23.0. It is not deprecated, experimental, or non-standard.

Next: R.ascendNatural()

Sort strings with embedded numbers in human-friendly order.

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