The Underscore.js _.rcurry3() method returns a curried version of the given function where a maximum of three arguments are processed from right to left.
Syntax:
_.rcurry3( 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, c) { return a/b/c; } var curried = _.rcurry3(div); console.log( "Curried division is :" , curried(4)(16)(256)); |
Output:
Curried division is : 4
Example 2:
// Defining underscore contrib variable var _ = require( 'underscore-contrib' ); // Function function sub(a, b, c) { return a-b-c; } var curried = _.rcurry3(sub); console.log( "Curried Subtraction is :" , curried(2)(4)(200)); |
Output:
Curried Subtraction is : 194
Example 3: Reversed Arguments are:
// Defining underscore contrib variable var _ = require( 'underscore-contrib' ); // Function function div(a, b, c) { return ( "a=" +a+ " and b=" +b+ " and c=" +c); } var curried = _.rcurry3(div); console.log(curried( "a" )( "b" )( "c" )); |
Output:
a=c and b=b and c=a