_group.js 457 B

12345678910111213141516
  1. import cb from './_cb.js';
  2. import each from './each.js';
  3. // An internal function used for aggregate "group by" operations.
  4. export default 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. }