Created
March 3, 2016 19:41
-
-
Save norcal82/6fdd3e62f97c39df274f to your computer and use it in GitHub Desktop.
Ruby Hash Methods
This file contains 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
def group_by_key_with_counts collection | |
collection.inject {|a, b| a.merge(b) { |_, old_val, new_val| old_val + new_val} } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment