Ramda.js R.minBy() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Relation

Definition

Ramda’s R.minBy() answers a projection selection question: which of two values wins when you compare them through a function f? You pass a unary projection, then two values, and get back one of the originals — whichever produces the smaller f result. It is not a Boolean test like R.eqBy. Cousin R.min compares values directly; R.maxBy picks the larger by projection. Previous helper is R.min. Next is R.pathEq.

The official sample is the whole idea. const square = n => n * n; then R.minBy(square, -3, 2) returns 2 because square(2) is 4 while square(-3) is 9. Raw numeric order would pick -3, but projection order picks 2. The result is always one of the two inputs, never f(a) or f(b).

Syntax

Call R.minBy. Start with this line.

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

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

Library declarations
Ramda
R.minBy(f, a, b)

Parameters

ParameterDescription
fRequired. Function. Unary projection applied to both a and b. Its results are compared for ordering.
aRequired. Any. First value. One of a or b is returned. Not mutated.
bRequired. Any. Second value to compare against. Not mutated.

Return Value

Return ValueDescription
Same type as inputsThe original a or b whose projection f(...) is smaller. Never f(a), never a Boolean.

Ramda Examples

📚 Getting Started

The official Ramda square sample and how projection order differs from direct comparison.

Example 1 — Official square Sample

From the Ramda docs. R.minBy compares projections and returns the original value, not f(result).

Ramda
const square = n => n * n;

R.minBy(square, -3, 2);
//=> 2
Try It Yourself

How It Works

That is the docs sample from ramdajs.com. square(2) is 4 and square(-3) is 9, so 2 wins. The result is 2, not 4.

Example 2 — vs R.min on the Same Pair

On (-3, 2), direct order picks -3. Projection order via square picks 2.

Ramda
const square = n => n * n;

R.min(-3, 2);
//=> -3

R.minBy(square, -3, 2);
//=> 2
Try It Yourself

How It Works

R.min compares -3 and 2 directly. R.minBy(square) compares 9 vs 4 and returns the original 2. Same pair, different question.

📈 Practical Patterns

Record selection by field, reduce minimum-by-key, then curried partial application.

Example 3 — R.minBy(R.prop('score'), userA, userB)

Pick the user record whose score field is lower. You get back the whole object, not just the score.

Ramda
const userA = { name: 'Ada', score: 92 };
const userB = { name: 'Grace', score: 88 };

R.minBy(R.prop('score'), userA, userB);
//=> { name: 'Grace', score: 88 }
Try It Yourself

How It Works

R.prop('score') extracts each score. 88 < 92, so the full userB record is returned. This is the idiomatic pattern for picking the record with the lower score by one field.

Example 4 — Minimum by Projection with R.reduce

Official list sample. Fold to the element with the smallest square. Empty list returns the seed.

Ramda
const square = n => n * n;

R.reduce(R.minBy(square), Infinity, [3, -5, 4, 1, -2]);
//=> 1

R.reduce(R.minBy(square), Infinity, []);
//=> Infinity
Try It Yourself

How It Works

R.reduce walks the list, keeping the element whose square is smallest. square(1) is 1, beating every other element. On an empty list the seed Infinity is returned unchanged.

Example 5 — Curried Partial Application with R.__

Fix the projection and one record. The placeholder waits for the other value in a pipeline.

Ramda
const userB = { name: 'Grace', score: 88 };
const pickUnderB = R.minBy(R.prop('score'), R.__, userB);

pickUnderB({ name: 'Ada', score: 92 });
//=> { name: 'Grace', score: 88 }

pickUnderB({ name: 'Alan', score: 70 });
//=> { name: 'Alan', score: 70 }
Try It Yourself

How It Works

R.minBy(R.prop('score'), R.__, userB) fixes the projection and the baseline record. Each call compares a new candidate against userB and returns whichever record has the lower score.

Browser Support

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

✓ Ramda 0.8.0+ · Any JS runtime

Ramda.js R.minBy()

Load Ramda 0.8.0 or later via CDN or npm, then call R.minBy with a projection function and two values. No extra browser API is required.

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

Bottom line: Safe in any project that includes Ramda 0.8.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.minBy(f, a, b) returns whichever of a or b produces the smaller result when passed to f. Type: Ord b => (a → b) → a → a → a. Arity 3, curried. Added in v0.8.0.
const square = n => n * n; R.minBy(square, -3, 2) returns 2 because square(2) is 4 and square(-3) is 9. The result is the original value, not the projection.
R.min compares a and b directly. R.minBy compares f(a) vs f(b) and returns the original a or b whose projection is smaller. On (-3, 2), R.min returns -3 while R.minBy(square) returns 2.
R.maxBy(fn, a, b) picks the larger by projection. R.eqBy(f, x, y) returns a Boolean when f(x) equals f(y). R.minBy picks the smaller original value by ordering on f.
Always the original a or b — never f(a) or f(b). You get back the winning input ready to use in pipelines.
No. R.minBy is a stable Ramda relation helper from v0.8.0. It is not deprecated, experimental, or non-standard.

Continue to R.pathEq()

Learn how R.pathEq checks a nested path against a value with R.equals — the usual way to filter records by zip code or flags.

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