title: How to group by array in JavaScript without external library?
body: <p>I want to group by that array to another array by name.</p>
  <pre><code>var cars = [
      {
          'name': 'audi',
          'model': 'r8',
          'year': '2012'
      }, {
          'name': 'audi',
          'model': 'rs5',
          'year': '2013'
      }, {
          'name': 'ford',
          'model': 'mustang',
          'year': '2012'
      }, {
          'name': 'ford',
          'model': 'fusion',
          'year': '2015'
      }
  ];
  </code></pre>
  <p>I expect that result (i omitted name inside <code>items</code> objects but I don't mind if you leave it there, if it would be to complicated (and slower):</p>
  <pre><code>var cars = [
   {
      name: 'audi',
      items: [
          {
              'model': 'r8',
              'year': '2012'
          }, {
              'model': 'rs5',
              'year': '2013'
          },
      ], 
    },
    {
      name: 'ford'
      items: [
          {
              'model': 'mustang',
              'year': '2012'
          }, {
              'model': 'fusion',
              'year': '2015'
          }
      ]
    }   
  ]
  </code></pre>
  <p>I was trying to achive that with <code>reduce</code></p>
  <pre><code>let group = cars.reduce((r, a) =&gt; {
    r[a.name] = [...r[a.name] || [], a];
    return r;
   }, {});
  </code></pre>
  <p>but it's far from my expectation, because haven't object with <code>name</code> property, and without <code>items</code> array.</p>