code: function collectRowsByLabel(rowsByLabel) {
    const labels = [...rowsByLabel.keys()].sort();
    const rows = [];
    for (const label of labels) {
      const cells = rowsByLabel.get(label) || [];
      if (cells.length === 0) continue;
      rows.push({label, cells});
    }
    return rows;
  }
docs: Convert Map<label, cells> to [{label, cells}].