| 28468 | |
| 28469 | // Generator function to create the findIndex and findLastIndex functions |
| 28470 | function createPredicateIndexFinder(dir) { |
| 28471 | return function(array, predicate, context) { |
| 28472 | predicate = cb(predicate, context); |
| 28473 | var length = getLength(array); |
| 28474 | var index = dir > 0 ? 0 : length - 1; |
| 28475 | for (; index >= 0 && index < length; index += dir) { |
| 28476 | if (predicate(array[index], index, array)) return index; |
| 28477 | } |
| 28478 | return -1; |
| 28479 | }; |
| 28480 | } |
| 28481 | |
| 28482 | // Returns the first index on an array-like that passes a predicate test |
| 28483 | _.findIndex = createPredicateIndexFinder(1); |