Project

General

Profile

Actions

Feature #11076

closed

Enumerable method count_by

Added by haraldb (Harald Böttiger) about 9 years ago. Updated almost 5 years ago.

Status:
Closed
Target version:
-
[ruby-core:<unknown>]

Description

I very often use Hash[array.group_by{|x|x}.map{|x,y|[x,y.size]}].

Would be nice with to have a method called count_by:

array = ['aa', 'aA', 'bb', 'cc']
p array.count_by(&:downcase) #=> {'aa'=>2,'bb'=>1,'cc'=>1}
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0