groupBy.js 367 B

12345678910
  1. var _group = require('./_group.js');
  2. var _has = require('./_has.js');
  3. // Groups the object's values by a criterion. Pass either a string attribute
  4. // to group by, or a function that returns the criterion.
  5. var groupBy = _group(function(result, value, key) {
  6. if (_has(result, key)) result[key].push(value); else result[key] = [value];
  7. });
  8. module.exports = groupBy;