Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptLodash _.flip2() Method

Lodash _.flip2() Method

The Lodash _.flip2() method returns a function that works identically to the given function but accepts the first two arguments in reverse order. The order of all rest arguments remains the same.

Syntax:

_.flip2( function );

Parameters: This method accepts a single parameter as mentioned above and defined below:

  • function: This method takes a function that takes some arguments.

Return Value: This method returns a function.

Note: To execute the below examples, you have to install the lodash-contrib library by using this command prompt and execute the following command.

npm install lodash-contrib

Below examples illustrate the Lodash _.flip2() method in JavaScript:

Example 1:

Javascript




// Defining lodash contrib variable
var _ = require('lodash-contrib'); 
  
function gfgFunc(a, b, c) {
    return "a = " + a + 
          ", b = " + b + 
          ", c = " + c;
}
  
var abc = _.flip2(gfgFunc);
  
console.log(abc(1, 2, 3));


Output:

a = 2, b = 1, c = 3

Example 2: 

Javascript




// Defining lodash contrib variable
var _ = require('lodash-contrib'); 
  
function gfgFunc(a, b) {
    return b + " : " + a;
}
  
var gfg = _.flip2(gfgFunc);
  
console.log(gfg("neveropen", "Computer Science Portal for Geeks"));


Output:

neveropen : Computer Science Portal for Geeks

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments