Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc.
The _.curryRight3() method returns a curried version of the given function where a maximum of three arguments are processed from right to left.
Syntax:
_.curryRight3( fun )
Parameters: This method takes a single parameter as listed above and discussed below:
- fun: This is the function that should be used in the curried version.
Return Value: This method returns a curried function.
Note: This method will not work in normal JavaScript because it requires the Lodash contrib library to be installed. The lodash-contrib library can be installed using npm install lodash-contrib –save
npm install lodash-contrib
Example 1:
Javascript
// Defining lodash contrib variable var _ = require( 'lodash-contrib' ); // Function to curry function div(a, b, c) { return a / b / c; } var curried = _.curryRight3(div); console.log( "Curried division is :" , curried(4)(32)(1000)); |
Output:
Curried division is : 7.8125
Example 2:
Javascript
// Defining lodash contrib variable var _ = require( 'lodash-contrib' ); // Function function div(a, b, c) { return a / b / c; } var curried = _.curryRight3(div); console.log( "Curried division is :" , curried(4)(1000)(10)); |
Output:
Curried division is : 0.0025
Example 3:
Javascript
// Defining lodash contrib variable var _ = require( 'lodash-contrib' ); // Function function sub(a, b, c) { return a - b - c; } var curried = _.curryRight3(sub); console.log( "Curried Subtraction is :" , curried(2)(10)(1000)); |
Output:
Curried Subtraction is : 988
Example 4:
Javascript
// Defining lodash contrib variable var _ = require( 'lodash-contrib' ); // Function function div(a, b, c) { return ( "a=" + a + " and b=" + b + " and c=" + c); } var curried = _.curryRight3(div); console.log(curried( "a" )( "b" )( "c" )); |
Output:
a=c and b=b and c=a