You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
766 B

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