You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
14 lines
352 B
14 lines
352 B
var safeCb = require('./safeCb'); |
|
exports = function(arr, predicate, ctx, dir) { |
|
dir = dir || 1; |
|
predicate = safeCb(predicate, ctx); |
|
var len = arr.length; |
|
var i = dir > 0 ? 0 : len - 1; |
|
while (i >= 0 && i < len) { |
|
if (predicate(arr[i], i, arr)) return i; |
|
i += dir; |
|
} |
|
return -1; |
|
}; |
|
|
|
module.exports = exports;
|
|
|