_group.js 475 B

1234567891011121314151617
  1. var _cb = require('./_cb.js');
  2. var each = require('./each.js');
  3. // An internal function used for aggregate "group by" operations.
  4. function group(behavior, partition) {
  5. return function(obj, iteratee, context) {
  6. var result = partition ? [[], []] : {};
  7. iteratee = _cb(iteratee, context);
  8. each(obj, function(value, index) {
  9. var key = iteratee(value, index, obj);
  10. behavior(result, value, key);
  11. });
  12. return result;
  13. };
  14. }
  15. module.exports = group;