_baseAggregator.js 746 B

12345678910111213141516171819202122
  1. var baseEach = require('./_baseEach');
  2. /**
  3. * Aggregates elements of `collection` on `accumulator` with keys transformed
  4. * by `iteratee` and values set by `setter`.
  5. *
  6. * @private
  7. * @param {Array|Object} collection The collection to iterate over.
  8. * @param {Function} setter The function to set `accumulator` values.
  9. * @param {Function} iteratee The iteratee to transform keys.
  10. * @param {Object} accumulator The initial aggregated object.
  11. * @returns {Function} Returns `accumulator`.
  12. */
  13. function baseAggregator(collection, setter, iteratee, accumulator) {
  14. baseEach(collection, function(value, key, collection) {
  15. setter(accumulator, value, iteratee(value), collection);
  16. });
  17. return accumulator;
  18. }
  19. module.exports = baseAggregator;