title: using ramda group by property and sum results on specified property
body: <p>I need help transforming an array of objects using ramda; I'd like to </p>
  
  <ol>
  <li>group by a specified property </li>
  <li>sum another property on the
  resulting set</li>
  </ol>
  
  <p>given an array like this:</p>
  
  <pre><code>var arr = [
    {
      title: "scotty",
      age: 22,
      score: 54,
      hobby: "debugging"
  
    },  {
      title: "scotty",
      age: 22,
      score: 19,
      hobby: "debugging"
    }
    ,  {
      title: "gabriel",
      age: 40,
      score: 1000
    }
  ];
  </code></pre>
  
  <p>if I want to group by <code>title</code> and sum on <code>age</code> it should return the following summary of values</p>
  
  <pre><code>var arr = [
    {
      title: "scotty",
      age: 44,
      hobby: "debugging",
    }
    ,  {
      title: "gabriel",
      age: 40,
      score: 1000
    }
  ];
  </code></pre>
  
  <p>when the unspecified property's differ in value they should be omitted, but if unspecified property's are the same in value it should remain in the final result.</p>
  
  <p>** My Solution **</p>
  
  <pre><code>    /*
   * [Student]
   */
  var arr = [
    {
      title: "scotty",
      age: 22,
      score: 54,
      hobby: "debugging"
  
    },  {
      title: "scotty",
      age: 22,
      score: 19,
      hobby: "debugging"
    }
    ,  {
      title: "gabriel",
      age: 40,
      score: 1000
    }
  ];
  
  
  /*
   * String -&gt; [[Student]] -&gt; [Student]
   */
  var sumOnProperty = function(property, v){
    var sum = (x,y) =&gt; x[property] + y[property];
    var new_array = [];
     v.forEach(arr =&gt; {
       if(arr.length &gt; 1){
          arr[0]["age"] = arr.reduce(sum)
          new_array.push(arr[0]);
       } else {
         if(arr.length != 0){
          new_array.push(arr[0]);
         }
       }
     })
    return new_array;
  }
  
  /*
   * String -&gt; String -&gt; [Student] -&gt; [Student]
   */
  var groupsumBy = function(groupproperty, sumproperty, arr){ 
  
         // create grouping
         var grouping = R.groupBy(R.prop(groupproperty), arr)
  
         // convert grouping object to array 
         var result1 = R.valuesIn(grouping);
  
         // sum each grouping and flatten 2d array
         var result2 = sumOnProperty(sumproperty, result1);
  
         return result2;
  }
  
  
  groupsumBy("title","age",arr);
  </code></pre>