Underscore.js _.flip2() Method

The _.flip2() method returns a function that works identically to 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 takes a function that takes some arguments.
Return Value: This method returns a function.
Note: This will not work in normal JavaScript because it requires the underscore.js contrib library to be installed.
underscore.js contrib library can be installed using npm install underscore-contrib –save.
Example 1:
Javascript
// Defining underscore contrib variable var _ = require('underscore-contrib'); function gfgFunc(a, b, c) { return "Value of a is " + a + " and Value of b is " + b + " and Value of c is " + c; } var abc = _.flip2(gfgFunc); console.log(abc(1, 2, 3)); |
Output:
Value of a is 2 and Value of b is 1 and Value of c is 3
Example 2:
Javascript
// Defining underscore contrib variable var _ = require('underscore-contrib'); function gfgFunc(a, b) { return b + " is " + a; } var gfg = _.flip2(gfgFunc); console.log(gfg("zambiatek",+ "Computer Science Portal for Geeks")); |
Output:
zambiatek is Computer Science Portal for Geeks
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek 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!



