Gathering counts of possibly duplicated items in an array
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
This comment has been minimized.
Another solution: