title: group dates by week javascript
body: <p>I have the array of Persian dates and I want to group dates by the week.
  for example, I have the following array:</p>
  
  <pre><code>[
      "1396-10-11 09:07:21",
      "1396-10-10 10:03:51",
      "1396-10-07 02:07:02",
      "1396-11-27 08:02:45",
      "1396-11-19 01:02:32",
      "1396-12-01 22:13:21",
      "1396-02-12 09:07:21",
      "1396-05-18 04:02:29",
      "1396-05-21 14:01:42",
      "1396-07-11 01:16:29"
  ]
  </code></pre>
  
  <p>and I want to groupBy dates by the week.</p>
  
  <p>I wrote following code but not working good:</p>
  
  <pre><code>Array.prototype.groupBy = function(prop) {
    return this.reduce(function(groups, item) {
      var val = item[prop];
      groups[val] = groups[val] || [];
      groups[val].push(item);
      return groups;
    }, {});
  }
  
  const formatted = dates.map(elem =&gt; {
    return { 
      numberOfWeek: moment(elem.date, 'jYYYY-jMM-jDD').startOf('jMonth').jWeek(),
      date: moment(elem.date, 'jYYYY-jMM-jDD').format('jYYYY-jMM-jDD'), 
      score: elem.score 
    };
  });
  </code></pre>