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

_createAggregator.js 789B

1234567891011121314151617181920212223
  1. var arrayAggregator = require('./_arrayAggregator'),
  2. baseAggregator = require('./_baseAggregator'),
  3. baseIteratee = require('./_baseIteratee'),
  4. isArray = require('./isArray');
  5. /**
  6. * Creates a function like `_.groupBy`.
  7. *
  8. * @private
  9. * @param {Function} setter The function to set accumulator values.
  10. * @param {Function} [initializer] The accumulator object initializer.
  11. * @returns {Function} Returns the new aggregator function.
  12. */
  13. function createAggregator(setter, initializer) {
  14. return function(collection, iteratee) {
  15. var func = isArray(collection) ? arrayAggregator : baseAggregator,
  16. accumulator = initializer ? initializer() : {};
  17. return func(collection, setter, baseIteratee(iteratee, 2), accumulator);
  18. };
  19. }
  20. module.exports = createAggregator;