title: How to reduce some data into a new array of objects?
body: <p><strong>update</strong>
  I tried my own solution and this is what I did maybe can be done better</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const dbData = [{
      studyId: 'X',
      siteId: 'A',
      day: '2000-01-01',
      status: 'PENDING_CALLCENTER',
      current: 5,
      total: 17,
    },
    {
      studyId: 'X',
      siteId: 'A',
      day: '2000-01-01',
      status: 'PENDING_SITE',
      current: 3,
      total: 9,
    },
    {
      studyId: 'Y',
      siteId: 'B',
      day: '2000-01-01',
      status: 'PENDING_SITE',
      current: 3,
      total: 9,
    },
    {
      studyId: 'Y',
      siteId: 'B',
      day: '2000-01-01',
      status: 'PENDING_SITE',
      current: 3,
      total: 9,
    },
    {
      studyId: 'Y',
      siteId: 'B',
      day: '2000-01-01',
      status: 'PENDING_CALLCENTER',
      current: 3,
      total: 9,
    },
  ];
  
  
  const reduced = dbData.reduce((acc, row) =&gt; {
    const {
      studyId,
      siteId,
      status,
      current,
      total
    } = row;
    const idx = acc.findIndex(x =&gt; studyId === x.studyId &amp;&amp; siteId === x.siteId);
    const item = idx === -1 ? {
      studyId,
      siteId,
      currents: {},
      totals: {}
    } : { ...acc[idx]
    };
    item.currents[status] = item.currents[status] ? item.currents[status] + current : current;
    item.totals[status] = item.totals[status] ? item.totals[status] + total : total;
    if (idx === -1) {
      acc.push(item);
    } else {
      acc[idx] = item;
    }
    return acc;
  }, []);
  
  console.log(reduced);</code></pre>
  </div>
  </div>
  </p>
  <p>I'm new to using reduce and I have some difficulties understanding how to use it correctly.</p>
  <p>I would like to solve a problem where I need to reduce some data in a new array of obj with a different shape.</p>
  <p>I have some data</p>
  <pre><code>[
        {
          studyId: 'X',
          siteId: 'A',
          day: '2000-01-01',
          status: 'PENDING_CALLCENTER',
          current: 5,
          total: 17,
        },
        {
          studyId: 'X',
          siteId: 'A',
          day: '2000-01-01',
          status: 'PENDING_SITE',
          current: 3,
          total: 9,
        },
      ];
  </code></pre>
  <p>I want to reduce this to this new data</p>
  <pre><code>[
        {
          studyId: 'X',
          siteId: 'A',
          currents: {
            PENDING_CALLCENTER: 5,
            PENDING_SITE: 3,
          },
          totals: {
            PENDING_CALLCENTER: 17,
            PENDING_SITE: 9,
          },
        },
      ];
  </code></pre>
  <p>To learn I was able to create a reducer which calc sum and that I did it but the above problem I have just difficulties to start and want to understand it.</p>