Equivalent to LINQ's Enumerable.First(predicate)
No need to reinvent the wheel, the correct way to do it is to use .find
:
var firstMatch = ['a', 'b', 'c'].find(applyConditions);
If you're using a browser that does not support .find
you can polyfill it
You could emulate this in the case where you want to return the first truthy value with reduce
.
['a', 'b', 'c'].reduce(function(prev, curr) {
return prev || predicate(curr) && curr;
}, false);
edit: made more terse with @BenjaminGruenbaum suggestion