Lodash _.overArgs() Method
Last Updated :
03 Nov, 2023
Lodash _.overArgs() method is used to create a function that invokes func with its arguments transformed using the given transforms function.
Syntax:
_.overArgs(func, transforms );
Parameters:
- func: This parameter holds the function to wrap.
- transforms: This parameter holds the function that specifies the argument transforms. It is an optional parameter.
Return Value:
This method returns the new function.
Example 1: In this example, we are using the lodash _.overArgs() method and passing two parameters to it, which is calling two other functions respectively and giving the output as an array in the console.
Javascript
const _ = require( "lodash" );
function Cube(number) {
return number * number * number;
}
function Triple(number) {
return number * 3;
}
let func = _.overArgs( function (a, b) {
return [a, b];
}, [Cube, Triple]);
console.log(func(3, 5));
|
Output:
[27, 15]
Example 2: In this example, we are using the lodash _.overArgs() method and passing two parameters to it, which is calling two other functions respectively and giving the output as an array in the console.
Javascript
const _ = require( "lodash" );
function doubled(number) {
return number * 2;
}
function square(number) {
return number * number;
}
let func = _.overArgs( function (a, b) {
return [a, b];
}, [square, doubled]);
console.log(func(5, 8));
|
Output:
[25, 16]
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...