findIndex.js
520 Bytes
var makeIterator = require('../function/makeIterator_');
/**
* Returns the index of the first item that matches criteria
*/
function findIndex(arr, iterator, thisObj){
iterator = makeIterator(iterator, thisObj);
if (arr == null) {
return -1;
}
var i = -1, len = arr.length;
while (++i < len) {
if (iterator(arr[i], i, arr)) {
return i;
}
}
return -1;
}
module.exports = findIndex;