Ramda.js R.max() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Relation

Definition

Ramda’s R.max() answers a selection question: which of two ordered values is larger? You pass two values and get back one of them — the larger. It uses JavaScript’s ordering rules under the hood, so numbers, strings, and Dates all work. It is not a Boolean test — cousins R.gt and R.gte tell you whether ordering holds. R.min picks the smaller value; R.maxBy picks by a computed key. R.clamp uses ordering internally to bound a value. Previous helper is R.lte. Next is R.maxBy.

The official samples cover the whole idea. R.max(789, 123) returns 789. R.max('a', 'b') returns 'b' because 'b' is lexicographically greater. The result is always one of the two inputs, ready to pipe forward.

Syntax

Call R.max. Start with this line.

Ramda
R.max(a, b)
CallWhat it does
R.max(a, b)Primary signature.
R.max(...)Call the relation helper.

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

Library declarations
Ramda
R.max(a, b)

Parameters

ParameterDescription
aRequired. Ord. First ordered value. One of a or b is returned. Not mutated.
bRequired. Ord. Second ordered value to compare against. Not mutated.

Return Value

Return ValueDescription
Ord (same type as inputs)The larger of a and b. Always one of the two inputs, never a Boolean.

Ramda Examples

📚 Getting Started

The official Ramda samples for numbers and strings.

Example 1 — Official Number and String Samples

Numbers and strings from the Ramda docs. R.max returns the larger value itself.

Ramda
R.max(789, 123);
//=> 789

R.max('a', 'b');
//=> 'b'
Try It Yourself

How It Works

That is the docs sample from ramdajs.com. 789 is greater than 123, so 789 is returned. Strings compare lexicographically: 'b' > 'a', so 'b' is returned.

Example 2 — vs R.gt and R.gte on the Same Pair

Compare value pickers with Boolean tests on (789, 123). Highlight: R.max returns the value; R.gt and R.gte return true.

Ramda
R.max(789, 123);
//=> 789

R.gt(789, 123);
//=> true

R.gte(789, 123);
//=> true
Try It Yourself

How It Works

All three helpers agree that 789 is the larger side, but they answer different questions. R.max gives you the value to use downstream. R.gt and R.gte only tell you the ordering relationship holds.

📈 Practical Patterns

Reduce maximum, floor-at-zero with placeholder, then later Date selection.

Example 3 — Maximum of a List with R.reduce

Fold a list to its largest element. R.max is the combiner; -Infinity is the identity for numbers.

Ramda
R.reduce(R.max, -Infinity, [3, -1, 7, 2]);
//=> 7
Try It Yourself

How It Works

R.reduce walks the list left to right, keeping the running maximum. Each step compares the accumulator with the next element via R.max. The final accumulator is 7.

Example 4 — Floor Negatives with R.max(R.__, 0)

Fix the floor at zero with the placeholder. Each list element is compared against 0; the larger value is kept.

Ramda
R.map(R.max(R.__, 0), [-3, 0, 5, -1]);
//=> [0, 0, 5, 0]
Try It Yourself

How It Works

R.max(R.__, 0) waits for the first argument. R.map passes each element. Negative values lose to 0; positives and zero pass through unchanged.

Example 5 — Pick the Later Date

Dates are ordered by their time values. R.max returns the later Date object.

Ramda
R.max(new Date('2024-06-01'), new Date('2024-01-01'));
//=> Date('2024-06-01')
Try It Yourself

How It Works

JavaScript coerces Dates to numbers when compared. June 2024 is later than January 2024, so the June Date object is returned. Use the result directly in pipelines that need the most recent timestamp.

Browser Support

R.max() is ordinary JavaScript once Ramda is loaded. Logos use the shared browser-image-sprite.png sprite from this project.

✓ Ramda 0.1.0+ · Any JS runtime

Ramda.js R.max()

Load Ramda 0.1.0 or later via CDN or npm, then call R.max with two ordered values. No extra browser API is required.

100% With Ramda 0.1.0+
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
R.max() Universal

Bottom line: Safe in any project that includes Ramda 0.1.0 or later. Use a CDN build such as ramda.min.js in the browser or install ramda from npm for Node. These labs use [email protected].

Frequently Asked Questions

R.max(a, b) returns the larger of its two arguments — the value itself, not a Boolean. Type: Ord a => a → a → a. Arity 2, curried. Added in v0.1.0.
R.max(789, 123) returns 789. R.max('a', 'b') returns 'b'. The result is always one of the two inputs.
R.max returns the larger value. R.gt and R.gte return true or false about ordering. On (789, 123), R.max gives 789 while R.gt and R.gte give true.
R.min returns the smaller value. R.maxBy(fn, a, b) picks the larger by a computed key via fn. R.max compares the values directly.
Yes. Any ordered type that JavaScript can compare works — numbers, strings (lexicographic), and Dates (by time value). R.max picks the later or lexicographically greater value.
No. R.max is a stable Ramda relation helper from v0.1.0. It is not deprecated, experimental, or non-standard.

Continue to R.maxBy()

Pick the larger item by a computed key — compare f(a) vs f(b) and get the original winner back.

R.maxBy() Method →

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.

6 people found this page helpful