For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/bigint/rangeRight.md.

rangeRight (for BigInts) es-toolkit

Returns the same BigInts as range, but in descending order.

const numbers = rangeRight(end);
const numbers = rangeRight(start, end);
const numbers = rangeRight(start, end, step);
Info

This function is available exclusively from es-toolkit/bigint to avoid potential conflicts with similar functions for other numeric types.

Usage

rangeRight(end)

Use rangeRight with one argument to count down from just below the end value to 0n.

import { rangeRight } from 'es-toolkit/bigint';

console.log(rangeRight(4n)); // [3n, 2n, 1n, 0n]
console.log(rangeRight(0n)); // []

Parameters

endbigintrequired

The end of the range, exclusive.

Returns

Returns an array of BigInts from just below end down to 0n.

bigint[]

rangeRight(start, end)

Use rangeRight with two arguments to count down to a start value other than 0n.

import { rangeRight } from 'es-toolkit/bigint';

console.log(rangeRight(2n, 5n)); // [4n, 3n, 2n]
console.log(rangeRight(-3n, 0n)); // [-1n, -2n, -3n]

Parameters

startbigintrequired

The start of the range, inclusive.

endbigintrequired

The end of the range, exclusive.

Returns

Returns an array of BigInts from just below end down to start.

bigint[]

rangeRight(start, end, step)

Use rangeRight with three arguments to step by something other than 1n. The values are exactly those of range with the same arguments, reversed.

import { range, rangeRight } from 'es-toolkit/bigint';

console.log(rangeRight(0n, 10n, 2n)); // [8n, 6n, 4n, 2n, 0n]
console.log(rangeRight(5n, 0n, -1n)); // [1n, 2n, 3n, 4n, 5n]

// Always the reverse of range with the same arguments
console.log(rangeRight(0n, 10n, 3n)); // [9n, 6n, 3n, 0n]
console.log(range(0n, 10n, 3n)); // [0n, 3n, 6n, 9n]

If the step points away from the end value, there is nothing to produce and you get an empty array.

import { rangeRight } from 'es-toolkit/bigint';

console.log(rangeRight(0n, 5n, -1n)); // []

Parameters

startbigintrequired

The start of the range, inclusive.

endbigintrequired

The end of the range, exclusive.

stepbigintoptional

The amount to count by. Defaults to 1n.

Returns

Returns the values of range(start, end, step) in descending order.

bigint[]

Throws

Throws an error if step is 0n.

Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.