_createPredicateIndexFinder.js 558 B

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