I have an array with some elements. How can I get the number of occurrences of each element in the array?
For example, given:
a = ['cat', 'dog', 'fish', 'fish']
The result should be:
a2 #=> {'cat' => 1, 'dog' => 1, 'fish' => 2}
How can I do that?