_createPredicateIndexFinder.js 509 B

12345678910111213141516
  1. import cb from './_cb.js';
  2. import getLength from './_getLength.js';
  3. // Internal function to generate `_.findIndex` and `_.findLastIndex`.
  4. export default function createPredicateIndexFinder(dir) {
  5. return function(array, predicate, context) {
  6. predicate = cb(predicate, context);
  7. var length = getLength(array);
  8. var index = dir > 0 ? 0 : length - 1;
  9. for (; index >= 0 && index < length; index += dir) {
  10. if (predicate(array[index], index, array)) return index;
  11. }
  12. return -1;
  13. };
  14. }