Last active
December 14, 2015 08:38
-
-
Save vagnerzampieri/5058908 to your computer and use it in GitHub Desktop.
Inject hash and sum.
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
| b = {"foo" => 100, "bar" => 300, "zaz" => 5} | |
| c = {"foo" => 200, "bar" => 8} | |
| a = [b, c] | |
| a.inject({}) { |memo, i| memo.merge(i) { |key, first, second| first + second } } | |
| => { | |
| "foo" => 300, | |
| "bar" => 308, | |
| "zaz" => 5 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment