Lodash _.flip() 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 _.flip() method is used to create a function that invokes the given func parameter with its arguments reversed.
Syntax:
_.flip( func )
Parameters: This method accepts a single parameter as mentioned above and described below:
- func: This parameter holds the function that takes some arguments.
Return Value: This method return the new flipped function.
Example 1:
Javascript
// Requiring the lodash library const _ = require( "lodash" ); function Func(a, b) { return b + " is " + a; } // Using the _.flip() method var gfg = _.flip(Func); console.log( gfg( "GeeksforGeeks" , "A Computer Science Portal for Geeks" ) ); |
Output:
"GeeksforGeeks is A Computer Science Portal for Geeks"
Example 2:
Javascript
// Requiring the lodash library const _ = require( "lodash" ); // Using the _.flip() method var flipped = _.flip( function () { return _.toArray(arguments); }); console.log( flipped( 'c' , 'cpp' , 'java' , 'python' ) ); |
Output:
['python', 'java', 'cpp', 'c']
Please Login to comment...