title: JavaScript - Group CSV fields based on empty cells
body: <p>I have data that come from a CSV file that can have blank fields and must have data grouped based on that.</p>
  <p>Here's a simple example of a data of persons by location. The location data only appears for the first person and every following person that don't have a location assigned belongs to the location that comes before:</p>
  <pre class="lang-js prettyprint-override"><code>&quot;Objects:&quot;, [{
      location: &quot;New York&quot;,
      date: &quot;10/10/2021&quot;,
      name: &quot;Max&quot;,
      surname: &quot;Payne&quot;
  }, {
      location: &quot;&quot;,
      date: &quot;&quot;,
      name: &quot;Duke&quot;,
      surname: &quot;Nuken&quot;
  }, {
      location: &quot;&quot;,
      date: &quot;&quot;,
      name: &quot;Jack&quot;,
      surname: &quot;Carver&quot;
  }, {
      location: &quot;Las Vegas&quot;,
      date: &quot;30/10/2021&quot;,
      name: &quot;Leon&quot;,
      surname: &quot;Kennedy&quot;
  }, {
      location: &quot;&quot;,
      date: &quot;&quot;,
      name: &quot;Donkey&quot;,
      surname: &quot;Kong&quot;
  }, {
      location: &quot;&quot;,
      date: &quot;&quot;,
      name: &quot;Ryu&quot;,
      surname: &quot;Hayabusa&quot;
  }]
  </code></pre>
  <p>I need to join the list of persons into a list and add it to the corresponding location:</p>
  <pre class="lang-js prettyprint-override"><code>&quot;Objects:&quot;, [{
      location: &quot;New York&quot;,
      date: &quot;10/10/2021&quot;,
      persons: [{
          name: &quot;Max&quot;,
          surname: &quot;Payne&quot;
      }, {
          name: &quot;Duke&quot;,
          surname: &quot;Nuken&quot;
      }, {
          name: &quot;Jack&quot;,
          surname: &quot;Carver&quot;
      }]
  }, {
      location: &quot;Las Vegas&quot;,
      date: &quot;30/10/2021&quot;,
      persons: [{
          name: &quot;Leon&quot;,
          surname: &quot;Kennedy&quot;
      }, {
          name: &quot;Donkey&quot;,
          surname: &quot;Kong&quot;
      }, {
          name: &quot;Ryu&quot;,
          surname: &quot;Hayabusa&quot;
      }]
  }]
  </code></pre>
  <p>The data originally comes as an array of arrays in this form:</p>
  <pre class="lang-js prettyprint-override"><code>const [headers, ...lines] = [
      [&quot;location&quot;,  &quot;date&quot;,       &quot;name&quot;,   &quot;surname&quot; ],
      [&quot;New York&quot;,  &quot;10/10/2021&quot;, &quot;Max&quot;,    &quot;Payne&quot;   ],
      [&quot;&quot;,          &quot;&quot;,           &quot;Duke&quot;,   &quot;Nuken&quot;   ],
      [&quot;&quot;,          &quot;&quot;,           &quot;Jack&quot;,   &quot;Carver&quot;  ],
      [&quot;Las Vegas&quot;, &quot;30/10/2021&quot;, &quot;Leon&quot;,   &quot;Kennedy&quot; ],
      [&quot;&quot;,          &quot;&quot;,           &quot;Donkey&quot;, &quot;Kong&quot;    ],
      [&quot;&quot;,          &quot;&quot;,           &quot;Ryu&quot;,    &quot;Hayabusa&quot;],
  ];
  </code></pre>
  <p>The code I currently have to convert the array into the first list of objects in this question  is this:</p>
  <pre class="lang-js prettyprint-override"><code>const locations = lines.map( (line) =&gt;
     line.reduce((object, value, index) =&gt;
          ({...object, [ headers[index] ]: value})
        , {}
     ));
  </code></pre>
  <p>What would be a good way to solve this?</p>