We would have all come across a situation where the number of conditional operators to be used in an expression is more like in the below example.
...
For further actions, you may consider blocking this person and/or reporting abuse
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
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?Absolutely we can use every and some.
Another way to group conditions is to group them in arrays where
for all conditions: [conditionsToCheck].every(x => x)
for at least one: [conditionsToCheck].some(x => x)
Yes, we can use it.
More optimized way.