baseFindIndex.js 709 B

1234567891011121314151617181920212223
  1. /**
  2. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  3. * support for callback shorthands and `this` binding.
  4. *
  5. * @private
  6. * @param {Array} array The array to search.
  7. * @param {Function} predicate The function invoked per iteration.
  8. * @param {boolean} [fromRight] Specify iterating from right to left.
  9. * @returns {number} Returns the index of the matched value, else `-1`.
  10. */
  11. function baseFindIndex(array, predicate, fromRight) {
  12. var length = array.length,
  13. index = fromRight ? length : -1;
  14. while ((fromRight ? index-- : ++index < length)) {
  15. if (predicate(array[index], index, array)) {
  16. return index;
  17. }
  18. }
  19. return -1;
  20. }
  21. module.exports = baseFindIndex;