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
