Skip to content

Instantly share code, notes, and snippets.

Created December 20, 2012 22:35
Show Gist options
  • Save anonymous/4349183 to your computer and use it in GitHub Desktop.
Save anonymous/4349183 to your computer and use it in GitHub Desktop.
l = [{"a" => 1, "b" => 2}, {"a" => 5, "b" => 8}]
k = %w(a b)
sums = k.map do |key|
[key, l.inject(0) {|memo, hash| memo + hash[key]}]
end
Hash[sums]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment