Underscore.js _.rcurry2() Method
Last Updated :
18 Sep, 2020
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:
var _ = require( 'underscore-contrib' );
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:
var _ = require( 'underscore-contrib' );
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:
var _ = require( 'underscore-contrib' );
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
Share your thoughts in the comments
Please Login to comment...