Lodash _.flip() Method
Last Updated :
03 Nov, 2023
Lodash _.flip() method is used to create a function that invokes the given func parameter with its arguments reversed.
Syntax:
_.flip( func );
Parameters:
- func: This parameter holds the function that takes some arguments.
Return Value:
This method returns the new flipped function.
Example 1: In this example, we are flipping the given values and putting them in an array then printing it into the console.
Javascript
const _ = require( "lodash" );
function Func(a, b) {
return b + " is " + a;
}
let gfg = _.flip(Func);
console.log(
gfg( "GeeksforGeeks" ,
"A Computer Science Portal for Geeks" )
);
|
Output:
"GeeksforGeeks is A Computer Science Portal for Geeks"
Example 2: In this example, we are flipping the given values and putting them in an array then printing it into the console.
Javascript
const _ = require( "lodash" );
let flipped = _.flip( function () {
return _.toArray(arguments);
});
console.log(
flipped( 'c' , 'cpp' , 'java' , 'python' )
);
|
Output:
['python', 'java', 'cpp', 'c']
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...