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.

32 lines
886 B

4 years ago
  1. var isArrayLike = require('./isArrayLike');
  2. /**
  3. * Creates a `baseEach` or `baseEachRight` function.
  4. *
  5. * @private
  6. * @param {Function} eachFunc The function to iterate over a collection.
  7. * @param {boolean} [fromRight] Specify iterating from right to left.
  8. * @returns {Function} Returns the new base function.
  9. */
  10. function createBaseEach(eachFunc, fromRight) {
  11. return function(collection, iteratee) {
  12. if (collection == null) {
  13. return collection;
  14. }
  15. if (!isArrayLike(collection)) {
  16. return eachFunc(collection, iteratee);
  17. }
  18. var length = collection.length,
  19. index = fromRight ? length : -1,
  20. iterable = Object(collection);
  21. while ((fromRight ? index-- : ++index < length)) {
  22. if (iteratee(iterable[index], index, iterable) === false) {
  23. break;
  24. }
  25. }
  26. return collection;
  27. };
  28. }
  29. module.exports = createBaseEach;