How do you count duplicates in a ruby array?
For example, if my array had three a's, how could I count that
Another version of a hash with a key for each element in your array and value for the count of each element
a = [ 1, 2, 3, 3, 4, 3] h = Hash.new(0) a.each { | v | h.store(v, h[v]+1) } # h = { 3=>3, 2=>1, 1=>1, 4=>1 }
1.4m articles
1.4m replys
5 comments
57.0k users