Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

_createBaseEach.js 886B

1234567891011121314151617181920212223242526272829303132
  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;