I'm trying to use lodash 2.4.1 in order to know if there's at least one element within an array with true
as its value.
So I decided to use lodash some
or any
function.
This is what my code looks like:
if ( _.some([lineup.reachesMaxForeignPlayers(), lineup.reachesBudgetLimit()], true) ) {
response.send(400, "La inclusión de este jugador no satisface las reglas del juego");
}
Which is never going inside the if block, even that first condition actually evaluates to true.
I got:
console.log(lineup.reachesMaxForeignPlayers());
console.log(lineup.reachesBudgetLimit());
Before the if
block and I can actually see first statement evaluating to true
.
What could it be failing?
I use lodash 2.4.1 as it's included Sails js dependency.
edit:
Actually, just using _.some
[docs] with no predicate defaults to identity:
_.some(bool_arr)
should work.
console.log(_.some([true, true, false]));
console.log(_.some([false, false, false]));
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/3.9.3/lodash.min.js"></script>
In addition to the other answers that suggest passing Boolean
as the predicate. You can also use:
_.some(bool_arr, _.identity)
_.identity
[docs]This method returns the first argument provided to it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With