title: Javascript - underscorejs map reduce groupby based on date
body: <p>I am working with underscorejs in a project. I need to do different types of array operations like map,reduce, filter groupby.</p>
  
  <p>My dataset looks like below:</p>
  
  <pre><code>var data_list = [
       {"insertDate": "2011-12-02T00:00","value": {"paisa":10000}},
      {"insertDate": "2013-03-02T00:00","value": {"paisa":10000}
      },{"insertDate": "2013-03-02T00:00","value": {"paisa":10000}
      },{"insertDate": "2012-12-02T00:00","value": {"paisa":30000}},
    {"insertDate": "2013-04-02T00:00","value": {"paisa":10000},
      },{"insertDate": "2013-04-02T00:00","value": {"paisa":30000}
      },{"insertDate": "2013-03-02T00:00","value": {"paisa":20000}},
    {"insertDate": "2013-04-12T00:00","value": {"paisa":30000}
      },
      {"insertDate": "2012-11-02T00:00","value": {"paisa":10000}}
  ]
  </code></pre>
  
  <p>I want to calculated data based on day, month and year.
  For day calculation I am doing groupby, then using map reduce for calculation.
  Like below:</p>
  
  <pre><code>var groupedByDateData = _.groupBy(data_list, "insertDate");
  var aggregateByDate = _.map(groupedByDateData, function(invoiceObject, createdat) {
    return { 
       createdat: createdat, 
       val: _.reduce(invoiceObject, function(m,x) { 
         return m + x.value.paisa;
       }, 0) 
    };
  });
  </code></pre>
  
  <p>Its working fine for day based map reduce, but for month and year calculation I want to do in same format as the code readable.</p>
  
  <p>How can I do map,reduce using underscorejs so that I can get data like below:
   For monthly calculation:</p>
  
  <pre><code>[{"createdat": "February 2011", "val": 10000}, 
  {"createdat": "March 2013", "val": 40000}, 
  {"createdat": "December 2012", "val": 30000}, 
  {"createdat": "April 2013", "val": 70000}, 
  {"createdat": "November 2012", "val": 10000}]
  </code></pre>
  
  <p>For yearly mapreduce:</p>
  
  <pre><code>[{"createdat": "2011", "val": 10000}, 
  {"createdat": "2013", "val": 110000}, 
  {"createdat": "2012", "val": 70000}]
  </code></pre>
  
  <p>My code <a href="http://jsbin.com/ucohoq/2/edit" rel="nofollow">JSBIN</a> here</p>
  
  <p>N.B: For getting yearly and monthly reduced result set I am splitting the date, but that is not best thing to do.
  check out my solution here <a href="http://jsbin.com/etepan/3/edit" rel="nofollow">http://jsbin.com/etepan/3/edit</a></p>
  
  <p>Thanks in advance.</p>