Lodash _.overSome() Method
Lodash _.overSome() method is used to create a function that checks if any of the predicates return truthy when invoked with the received arguments.
Syntax:
_.overSome( predicates )
Parameters:
This method accepts one parameter as mentioned above and described below:
- predicates: This is the predicate to invoke.
Return Value:
This method returns a new function.
Example 1: In this example, the code requires the Lodash library and employs the _.overSome
method to create a composite function that checks if at least one of the provided functions (Boolean
and isFinite
) returns true for different input values
Javascript
// Requiring the lodash library const _ = require( "lodash" ); // Use of _.overSome() method let func = _.overSome([Boolean, isFinite]); // Saving the result let gfg1 = func(10); let gfg2 = func(-5); let gfg3 = func( null ); let gfg4 = func(NaN); // Printing the output console.log(gfg1); console.log(gfg2); console.log(gfg3); console.log(gfg4); |
Output:
true
true
true
false
Example 2: In this example, the code utilizes Lodash’s _.overSome
method to create a function that checks if at least one of the provided functions (Math.min and Math.max) returns true for a set of values and then displays the result in the console.
Javascript
// Requiring the lodash library const _ = require( "lodash" ); // Use of _.overSome() method let func = _.overSome([(Math.min, Math.max)]); // Saving the result let gfg = func(2, 4, -6, 8); // Printing the output console.log(gfg); |
Output:
true
Contact Us