Lodash _.curryRight() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc.
The _.curryRight() method is used to return a curried version of the given function where the given arguments are processed from right to left.
Syntax:
_.curryRight( 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 the 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
Example 1:
Javascript
// Defining lodash contrib variablevar _ = require('lodash-contrib'); // Function to curryfunction div(a, b, c) { return a / b / c;} // Using the _.curryRight() methodvar curried = _.curryRight(div); console.log("Curried division is :", curried(3)(3)(99)); |
Output:
Curried division is : 11
Example 2:
Javascript
// Defining lodash contrib variablevar _ = require('lodash-contrib'); // Function to curryfunction div(a, b, c, d) { return a - b - c - d;} // Using the _.curryRight() methodvar curried = _.curryRight(div); console.log("Curried Subtraction is :", curried(2)(1)(6)(44)); |
Output:
Curried Subtraction is : 35
Example 3:
Javascript
// Defining lodash contrib variablevar _ = require('lodash-contrib'); // Function to curryfunction div(a, b, c) { return ("a=" + a + " and b=" + b + " and c=" + c);} // Using the _.curryRight() methodvar curried = _.curryRight(div); console.log(curried("a")("b")("c")); |
Output:
a=c and b=b and c=a


