_group.js 483 B

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