_baseInverter.js 736 B

12345678910111213141516171819202122
  1. var baseForOwn = require('./_baseForOwn');
  2. /**
  3. * The base implementation of `_.invert` and `_.invertBy` which inverts
  4. * `object` with values transformed by `iteratee` and set by `setter`.
  5. *
  6. * @private
  7. * @param {Object} object The object to iterate over.
  8. * @param {Function} setter The function to set `accumulator` values.
  9. * @param {Function} iteratee The iteratee to transform values.
  10. * @param {Object} accumulator The initial inverted object.
  11. * @returns {Function} Returns `accumulator`.
  12. */
  13. function baseInverter(object, setter, iteratee, accumulator) {
  14. baseForOwn(object, function(value, key, object) {
  15. setter(accumulator, iteratee(value), key, object);
  16. });
  17. return accumulator;
  18. }
  19. module.exports = baseInverter;