_.countBy

countBy_.countBy(list, iteratee, [context])
Sorts a list into groups and returns a count for the number of objects in each group. Similar to groupBy, but instead of returning a list of values, returns a count for the number of values in that group.

_.countBy([1, 2, 3, 4, 5], function(num) {
  return num % 2 == 0 ? 'even': 'odd';
});
=> {odd: 3, even: 2}
doc_Underscore
2016-04-09 09:05:19
Comments
Leave a Comment

Please login to continue.