您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

27 行
649 B

4 年前
  1. import calculateCellWidthIndex from './calculateCellWidthIndex';
  2. /**
  3. * Produces an array of values that describe the largest value length (width) in every column.
  4. *
  5. * @param {Array[]} rows
  6. * @returns {number[]}
  7. */
  8. export default (rows) => {
  9. if (!rows[0]) {
  10. throw new Error('Dataset must have at least one row.');
  11. }
  12. const columns = new Array(rows[0].length).fill(0);
  13. rows.forEach((row) => {
  14. const columnWidthIndex = calculateCellWidthIndex(row);
  15. columnWidthIndex.forEach((valueWidth, index0) => {
  16. if (columns[index0] < valueWidth) {
  17. columns[index0] = valueWidth;
  18. }
  19. });
  20. });
  21. return columns;
  22. };