How to use the rangeRight function from lodash

Find comprehensive JavaScript lodash.rangeRight code examples handpicked from public code repositorys.

lodash.rangeRight is a function in the Lodash library that creates an array of numbers in reverse order, similar to lodash.range but with the ability to specify a start and end point in reverse order.

311
312
313
314
315
316
317
318
319
320
module.exports.pullAt              = _.pullAt;
module.exports.quaternary          = _.quaternary;
module.exports.rCurry              = _.rCurry;
module.exports.random              = _.random;
module.exports.range               = _.range;
module.exports.rangeRight          = _.rangeRight;
module.exports.rcurry2             = _.rcurry2;
module.exports.rcurry3             = _.rcurry3;
module.exports.rearg               = _.rearg;
module.exports.reduce              = _.reduce;
fork icon19
star icon122
watch icon0

+ 92 other calls in file

950
951
952
953
954
955
956
957
958
959
960
961
962
console.log(propertyOf({ 'a': { 'b': 2 } })); // => 2


const range = _.range(4);
console.log(range); // => [0, 1, 2, 3]


const rangeRight = _.rangeRight(-4);
console.log(rangeRight); // => [0, -1, -2, -3]


const runInContext = _.runInContext();
console.log(runInContext); // => [Function: runInContext]
fork icon0
star icon4
watch icon0

+ 15 other calls in file

How does lodash.rangeRight work?

lodash.rangeRight works by creating an array of numbers in reverse order, similar to lodash.range but with the ability to specify a start and end point in reverse order.

The function takes up to three arguments: a start value, an end value (inclusive), and a step value that specifies the interval between numbers in the range.

If only one argument is provided, it is used as the end value, and start is set to 0.

If two arguments are provided, they are used as start and end, respectively, and step is set to 1.

If start is greater than end, the resulting array is created in reverse order.

By using lodash.rangeRight, developers can easily create an array of numbers in reverse order with a specified start and end point, which can be useful for generating sequences of numbers or creating ranges for iteration.

Ai Example

1
2
3
4
const _ = require("lodash");

const range = _.rangeRight(0, 10, 2);
console.log(range);

In this example, we use lodash.rangeRight to create an array of numbers in reverse order. We call _.rangeRight(0, 10, 2) to create an array that starts at 0, ends at 10 (inclusive), and increments by 2. The resulting array is [8, 6, 4, 2, 0], which is created in reverse order due to the use of rangeRight. We store the resulting array in a variable called range and log it to the console. By using lodash.rangeRight in this way, we can easily create arrays of numbers in reverse order with a specified start and end point, which can be useful for generating sequences of numbers or creating ranges for iteration.

Other functions in lodash

Sorted by popularity

function icon

lodash.get is the most popular function in lodash (7670 examples)