Created
May 31, 2015 03:18
-
-
Save siruguri/5502174cf9d61219e1b3 to your computer and use it in GitHub Desktop.
Gathering counts of possibly duplicated items in an array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [1, 1, 1, 2, 3, 3, 4, 4, 4, 4] | |
b = a.uniq | |
counts = b.inject({}) do |memo, key| | |
memo[key] = a.count(key) | |
memo | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Another solution: