Ramda.js R.modulo() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Math

Definition

Ramda’s R.modulo() divides the first number by the second and returns the remainder. The official docs sample is R.modulo(17, 3) → 2. Added in v0.1.1. See also R.mathMod.

Internally that is JavaScript a % b. Remainders can be negative when the dividend is negative — the docs call that out on purpose. For a remainder that stays in 0 … modulus-1, switch to R.mathMod.

Syntax

Call R.modulo. Start with this line.

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

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

Library declarations
Ramda
R.modulo(a, b)

Parameters

ParameterDescription
aRequired. the dividend (the value being divided). First argument.
bRequired. the divisor, sometimes called the modulus. Second argument.

Return Value

Return ValueDescription
*Returns a Number: a % b.

Ramda Examples

📚 Getting Started

The official 17 % 3 sample, then the official JavaScript-style signs.

Example 1 — The Official Docs Example

From ramdajs.com/docs/#modulo: R.modulo(17, 3) returns 2.

Ramda
R.modulo(17, 3);  //=> 2
R.modulo(10, 4);  //=> 2
R.modulo(9, 3);   //=> 0
R.modulo(17)(3);  //=> 2 (curried)
Try It Yourself

How It Works

R.modulo returns a % b. 17 / 3 is 5 remainder 2 — the official sample. 9 % 3 is 0 because 9 divides evenly. Argument order is dividend first, then divisor.

Example 2 — Official JavaScript-Style Signs

The docs show that Ramda keeps JavaScript remainder signs, not mathematical modulo.

Ramda
R.modulo(-17, 3);  //=> -2
R.modulo(17, -3);  //=> 2
R.modulo(-17, -3); //=> -2
Try It Yourself

How It Works

JavaScript % copies the sign of the dividend. A negative first argument can yield a negative remainder — official sample -2. That is why wrapping a negative index with R.modulo can land on a negative slot. Use R.mathMod when you need 0 … n-1.

📈 Practical Patterns

Official isOdd helper, filtering odds, and mathematical modulo.

Example 3 — Official isOdd with R.__

The docs build a reusable remainder-by-2 function by filling the divisor and waiting for the dividend.

Ramda
var isOdd = R.modulo(R.__, 2);

isOdd(42);  //=> 0
isOdd(21);  //=> 1

// Without the placeholder, R.modulo(2) waits for the divisor:
R.modulo(2)(5);  //=> 2 % 5  (not n % 2)
Try It Yourself

How It Works

R.__ says “skip this slot.” R.modulo(R.__, 2) stores the divisor 2 and waits for a. Even numbers return 0; odd positives return 1. Plain R.modulo(2) stores the dividend instead, so R.modulo(2)(5) is 2 % 5.

Example 4 — Filter Odds and Map Remainders

Drop the official isOdd helper into R.filter (0 is falsy, 1 is truthy), then map remainders by 3.

Ramda
var isOdd = R.modulo(R.__, 2);
var rem3 = R.modulo(R.__, 3);

R.filter(isOdd, [1, 2, 3, 4, 5]);
//=> [1, 3, 5]

R.map(rem3, [1, 2, 3, 4, 5, 6]);
//=> [1, 2, 0, 1, 2, 0]
Try It Yourself

How It Works

R.filter keeps items whose remainder is truthy, so 1 stays and 0 is dropped. rem3 is a one-argument function, exactly the shape R.map wants. Each list item becomes the dividend; the divisor stays 3.

Example 5 — R.modulo vs R.mathMod

The docs pair these two. Mathematical modulo stays non-negative; JavaScript remainder does not.

Ramda
R.modulo(-17, 5);   //=> -2
R.mathMod(-17, 5);  //=> 3

R.modulo(17, 0);    //=> NaN
R.mathMod(17, 0);   //=> NaN
Try It Yourself

How It Works

-17 % 5 is -2 in JavaScript, so R.modulo returns that. R.mathMod(-17, 5) returns 3 because -2 + 5 = 3 — the official mathematical sample. Both yield NaN when the modulus is 0. R.mathMod also returns NaN for a negative or non-integer modulus.

Browser Support

R.modulo() is plain JavaScript remainder — it runs anywhere Ramda loads: every modern browser plus Node.js. Logos use the shared browser-image-sprite.png sprite from this project.

✓ Ramda 0.1.1+ · Any JS runtime

Ramda.js R.modulo()

Load Ramda via CDN or npm, then call R.modulo(a, b). Because it only uses a % b, behavior is identical across engines.

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

Bottom line: Safe in any project that includes Ramda. Use a CDN build such as ramda.min.js in the browser or install ramda from npm for Node.

Frequently Asked Questions

R.modulo(a, b) returns the remainder of a divided by b — the same as JavaScript's a % b operator. It is Ramda's curried remainder helper, so you can partially apply it and drop it into R.map, R.filter, or R.pipe.
R.modulo(17, 3) returns 2. The docs also show JavaScript-style signs: R.modulo(-17, 3) returns -2 and R.modulo(17, -3) returns 2. Then const isOdd = R.modulo(R.__, 2) with isOdd(42) returning 0 and isOdd(21) returning 1. Added in v0.1.1. See also R.mathMod.
Yes. R.modulo has arity 2 and is automatically curried, so R.modulo(17, 3) and R.modulo(17)(3) both return 2. Calling it with one argument returns a function that waits for the divisor.
R.__ is Ramda's placeholder. R.modulo(R.__, 2) fills the second argument (the divisor) and waits for the first. That is how the official isOdd helper works: isOdd(n) is n % 2.
R.modulo follows JavaScript % and can return a negative remainder: R.modulo(-17, 5) is -2. R.mathMod is mathematical modulo and stays non-negative for a positive modulus: R.mathMod(-17, 5) is 3. mathMod also requires integers and returns NaN for a zero or negative modulus.
No. R.modulo is a stable Ramda math helper from v0.1.1. It is not deprecated, experimental, or non-standard.

Review R.divide()

Quotients and remainders are a pair — divide after you know leftover math.

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

6 people found this page helpful