| 612 | |
| 613 | // Generator function to create the findIndex and findLastIndex functions |
| 614 | function createPredicateIndexFinder(dir) { |
| 615 | return function(array, predicate, context) { |
| 616 | predicate = cb(predicate, context); |
| 617 | var length = getLength(array); |
| 618 | var index = dir > 0 ? 0 : length - 1; |
| 619 | for (; index >= 0 && index < length; index += dir) { |
| 620 | if (predicate(array[index], index, array)) return index; |
| 621 | } |
| 622 | return -1; |
| 623 | }; |
| 624 | } |
| 625 | |
| 626 | // Returns the first index on an array-like that passes a predicate test |
| 627 | _.findIndex = createPredicateIndexFinder(1); |