countBy.js 340 B

123456789
  1. import group from './_group.js';
  2. import has from './_has.js';
  3. // Counts instances of an object that group by a certain criterion. Pass
  4. // either a string attribute to count by, or a function that returns the
  5. // criterion.
  6. export default group(function(result, value, key) {
  7. if (has(result, key)) result[key]++; else result[key] = 1;
  8. });