Last Updated: February 25, 2016
·
486
· dipil-saud

Get count of individual items in an array

array.inject(Hash.new(0)){|result, element| result[element] += 1; result }

["a", "b", "a", "c", "d", "a", "b"] => {"a"=>3, "b"=>2, "c"=>1, "d"=>1}