I want to return the index of the first element satisfying a unary predicate.
Example:
[1,2,3,4,5,6,7].indexOf((x) => x % 3 === 0) // returns 2
Is there such a function? The alternative I was going to use was
[1,2,3,4,5,6,7].reduce((retval,curelem,idx) =>
{
if(curelem % 3 === 0 && retval === undefined)
retval = idx;
return retval;
}, undefined);
but of course that would be less efficient since it doesn't stop iterating through the array after it has found the element.