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

_baseReduce.js 909B

1234567891011121314151617181920212223
  1. /**
  2. * The base implementation of `_.reduce` and `_.reduceRight`, without support
  3. * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
  4. *
  5. * @private
  6. * @param {Array|Object} collection The collection to iterate over.
  7. * @param {Function} iteratee The function invoked per iteration.
  8. * @param {*} accumulator The initial value.
  9. * @param {boolean} initAccum Specify using the first or last element of
  10. * `collection` as the initial value.
  11. * @param {Function} eachFunc The function to iterate over `collection`.
  12. * @returns {*} Returns the accumulated value.
  13. */
  14. function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
  15. eachFunc(collection, function(value, index, collection) {
  16. accumulator = initAccum
  17. ? (initAccum = false, value)
  18. : iteratee(accumulator, value, index, collection);
  19. });
  20. return accumulator;
  21. }
  22. module.exports = baseReduce;