Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

calculateMaximumColumnWidthIndex.js.flow 649B

123456789101112131415161718192021222324252627
  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. };