createFindIndex.js 594 B

123456789101112131415161718192021
  1. var baseCallback = require('./baseCallback'),
  2. baseFindIndex = require('./baseFindIndex');
  3. /**
  4. * Creates a `_.findIndex` or `_.findLastIndex` function.
  5. *
  6. * @private
  7. * @param {boolean} [fromRight] Specify iterating from right to left.
  8. * @returns {Function} Returns the new find function.
  9. */
  10. function createFindIndex(fromRight) {
  11. return function(array, predicate, thisArg) {
  12. if (!(array && array.length)) {
  13. return -1;
  14. }
  15. predicate = baseCallback(predicate, thisArg, 3);
  16. return baseFindIndex(array, predicate, fromRight);
  17. };
  18. }
  19. module.exports = createFindIndex;