title: Array get sum of all children bottom up
body: <p>I have an javascript array which looks like this :</p>
  
  <pre><code>[
      {
          used : 24000,
          service : service A,
          parent : service B,
      },
      {
          used : 450,
          service : service B,
          parent : service C,
      },
      ...
  ]
  </code></pre>
  
  <p>I would like to iterate over the array to get the sum of each service child. For example if a service got A and B as a child, then its used attribute will be its own used + the sum of his child used.
  As a consequence, I need to get the deepest services in the hierarchy first.</p>
  
  <p>Then final output could be : </p>
  
  <pre><code>[
      {
          used : 24000,
          service : service A,
          parent : service B,
      },
      {
          used : 24450, //Sum here has changed
          service : service B,
          parent : service C,
      },
      ...
  ]
  </code></pre>
  
  <p>One last thing, the top service doesn't always have a null parent...</p>
  
  <p>If need I can transform the array into a hierarchical one</p>
  
  <p>Does anyone have a good algorithm which can do such a thing (posssibly in javascript, but pseudo code is cool too) ?</p>