Hi @kvharish
, I like what you are trying to do, however wouldn't it be better to make use of the array functions like every or some?, that way you eliminate the need for an additional function:
constfirstCondition=true,secondCondition=true,thirdCondition=true;constconditionArray=[firstCondition,secondCondition,thirdCondition];if(conditionArray.every(contition=>condition)){console.log("All the conditions met expectation");}else{console.log("All the conditions did not meet expectation");}if(conditionArray.some(condition=>condition)){console.log("Atleast one of the conditions met expectation");}else{console.log("None of the conditions met the expectation");}
And just because I love lazy evaluation you could even turn those conditions into predicates:
Hi @kvharish , I like what you are trying to do, however wouldn't it be better to make use of the array functions like
every
orsome
?, that way you eliminate the need for an additional function:And just because I love lazy evaluation you could even turn those conditions into predicates:
That way conditions are not evaluated until you need them to.
Regards
Absolutely we can use every and some.
Definitely agree using
every
andsome
are the way to go. You could simplify further by usingBoolean
like so,conditionArray.every(Boolean)
Nice, haven't tried it, however, won't it evaluate as true for
Boolean
being an object?