Lodash _.curryRight3() 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 _.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

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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));

chevron_right


Output:

Curried division is : 7.8125

Example 2:

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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));

chevron_right


Output: 

Curried division is : 0.0025

Example 3:

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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));

chevron_right


Output: 

Curried Subtraction is : 988

Example 4:

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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"));

chevron_right


Output: 

a=c and b=b and c=a

full-stack-img




My Personal Notes arrow_drop_up

Recommended Posts:

    Article Tags :

    Be the First to upvote.


    Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.