title: How to sum values in a nested array based on element values
body: <p>I have an array of hashes:</p>
  
  <pre><code>[{:metric_type=&gt;"gender", :key=&gt;"female", :value=&gt;1.0},
   {:metric_type=&gt;"gender", :key=&gt;"male", :value=&gt;2},
   {:metric_type=&gt;"gender", :key=&gt;"female", :value=&gt;3.0},
   {:metric_type=&gt;"gender", :key=&gt;"male", :value=&gt;4.0},
   {:metric_type=&gt;"gender", :key=&gt;"female", :value=&gt;5.5},
   {:metric_type=&gt;"gender", :key=&gt;"male", :value=&gt;6.5},
   {:metric_type=&gt;"gender", :key=&gt;"female", :value=&gt;7.5},
   {:metric_type=&gt;"gender", :key=&gt;"male", :value=&gt;8.5},
   {:metric_type=&gt;"gender", :key=&gt;"female", :value=&gt;9},
   {:metric_type=&gt;"gender", :key=&gt;"male", :value=&gt;10.5},
   {:metric_type=&gt;"gender", :key=&gt;"female", :value=&gt;11},
   {:metric_type=&gt;"gender", :key=&gt;"male", :value=&gt;12.5},
   {:metric_type=&gt;"gender", :key=&gt;"female", :value=&gt;13.1},
   {:metric_type=&gt;"gender", :key=&gt;"male", :value=&gt;14.5}]
  </code></pre>
  
  <p>And I would like to loop through each of these elements and sum the values based on the values that are assigned to the other two keys, <code>:metric_type</code> and <code>:key</code>, and am trying to get results that look like this:</p>
  
  <pre><code>[{:metric_type=&gt;"gender", :key=&gt;"female", :value=50.1},
  {:metric_type=&gt;"gender", :key=&gt;"male", :value=&gt;58.5}]
  </code></pre>
  
  <p>I played around with <code>inject</code> and <code>reduce</code> but have not been able to come up with what I am looking for.</p>