Wednesday, September 17, 2025
HomeLanguagesJavascriptUnderscore.js _.rcurry2() Method

Underscore.js _.rcurry2() Method

The Underscore.js _.rcurry2() method returns a curried version of the given function where a maximum of two arguments are processed from right to left.

Syntax:

_.rcurry2( fun )

Parameters: This method takes a single parameter as listed above and discussed below:

  • fun: This is the given function passed as parameter.

Return Value: This method returns a curried function.

Note: To execute the below examples, you have to install the underscore-contrib library by using this command prompt and execute the following command.

npm install underscore-contrib

Example 1: 




// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
  
// Function
function div(a, b) {
    return a/b;
}
  
var curried = _.rcurry2(div);
  
console.log("Curried division is :", 
    curried(4)(16));


Output:

Curried division is : 4

Example 2:




// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
  
// Function
function sub(a, b) {
    return a-b;
}
  
var curried = _.rcurry2(sub);
  
console.log("Curried Subtraction is :", 
    curried(2)(4));


Output: 

Curried Subtraction is : 2

Example 3: Reversed Arguments shown below:




// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
  
// Function
function div(a, b) {
    return ("a="+a+" and b="+b);
}
  
var curried = _.rcurry2(div);
  
console.log(curried("a")("b"));


Output: 

a=b and b=a
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32299 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6660 POSTS0 COMMENTS
Nicole Veronica
11833 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11895 POSTS0 COMMENTS
Shaida Kate Naidoo
6779 POSTS0 COMMENTS
Ted Musemwa
7050 POSTS0 COMMENTS
Thapelo Manthata
6735 POSTS0 COMMENTS
Umr Jansen
6741 POSTS0 COMMENTS