Underscore.js _.curry2() Method
Last Updated :
18 Sep, 2020
The Underscore.js _.curry2() method returns a curried version of the given function but will curry exactly two arguments, no more or less.
Syntax:
_.curry2( 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: It returns a curried version of the 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 fun(a, b) {
return a*b;
}
var gfgFunc = _.curry2(fun);
console.log( "Multiplication is :" ,
gfgFunc(20)(23));
|
Output:
Multiplication is : 460
Example 2:
var _ = require( 'underscore-contrib' );
function fun(a, b) {
return a-b;
}
var gfgFunc = _.curry2(fun);
console.log( "Subtraction is :" ,
gfgFunc(25)(23));
|
Output:
Subtraction is : 2
Example 3: Printing the arguments taken by the curry2() function.
var _ = require( 'underscore-contrib' );
function fun(x, y) {
return arguments;
}
var gfgFunc = _.curry2(fun);
console.log( "Curried Arguments are :" ,
gfgFunc( "a" )( "b" ));
|
Output:
Curried Arguments are : [Arguments] { '0': 'a', '1': 'b' }
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...