function scols(arr) {
  let schema = [];
  let outArr = [];
  let colWidths = [];

  if (!Array.isArray(arr)) {
    throw 'Attempt to print non-array value';
  }

  if (arr.length < 1) {
    throw 'No columns for array detected'
  }

  for (let prop in arr[0]) {
    if (arr[0].hasOwnProperty(prop)) {
      schema.push(prop);
      colWidths.push(prop.length >= 1 ? prop.length + 1 : 1);
    }
  }

  for (let i = 0; i < arr.length; i++) {
    let newElt = [];
    for (let j = 0; j < schema.length; j++) {
      let str = sprint_go(arr[i][schema[j]], {}, 1);
      if (colWidths[j] < str.length + 1) {
        colWidths[j] = str.length + 1;
      }
      newElt.push(str);
    }
    outArr.push(newElt);
  }

  let output = '\n';
  for (let i = 0; i < schema.length; i++) {
    output += schema[i].padStart(colWidths[i], ' ');
  }
  output += '\n';
  for (let i = 0; i < outArr.length; i++) {
    for (let j = 0; j < schema.length; j++) {
      output += outArr[i][j].padStart(colWidths[j], ' ');
    }
    output += '\n';
  }
  return output;
}
/**
 * Returns a string containing a tabular representation of the given array.
 * The given array is an array of objects.  Each property is one column in
 * the table. The first element is assumed to contain exactly the properties
 * to be printed. If subsequent elements are missing some of those properties,
 * an exception will be thrown.  If subsequent elements have additional
 * properties, they will not be printed.
 *
 * @param {*} arr The array to print in tabular form.
 */
Returns a string containing a tabular representation of the given array.
The given array is an array of objects.  Each property is one column in
the table. The first element is assumed to contain exactly the properties
to be printed. If subsequent elements are missing some of those properties,
an exception will be thrown.  If subsequent elements have additional
properties, they will not be printed.

@param {*} arr The array to print in tabular form.
Returns a string containing a tabular representation of the given array . The given array is an array of objects . Each property is one column in the table . The first element is assumed to contain exactly the properties to be printed . If subsequent elements are missing some of those properties an exception will be thrown . If subsequent elements have additional properties they will not be printed . @param { * } arr The array to print in tabular form .
function scols(arr) {
  let schema = [];
  let outArr = [];
  let colWidths = [];
  if (!Array.isArray(arr)) {
    throw 'Attempt to print non-array value';
  }
  if (arr.length < 1) {
    throw 'No columns for array detected'
  }
  for (let prop in arr[0]) {
    if (arr[0].hasOwnProperty(prop)) {
      schema.push(prop);
      colWidths.push(prop.length >= 1 ? prop.length + 1 : 1);
    }
  }
  for (let i = 0; i < arr.length; i++) {
    let newElt = [];
    for (let j = 0; j < schema.length; j++) {
      let str = sprint_go(arr[i][schema[j]], {}, 1);
      if (colWidths[j] < str.length + 1) {
        colWidths[j] = str.length + 1;
      }
      newElt.push(str);
    }
    outArr.push(newElt);
  }
  let output = '\n';
  for (let i = 0; i < schema.length; i++) {
    output += schema[i].padStart(colWidths[i], ' ');
  }
  output += '\n';
  for (let i = 0; i < outArr.length; i++) {
    for (let j = 0; j < schema.length; j++) {
      output += outArr[i][j].padStart(colWidths[j], ' ');
    }
    output += '\n';
  }
  return output;
}
function scols ( arr ) { let schema = [ ] ; let outArr = [ ] ; let colWidths = [ ] ; if ( ! Array . isArray ( arr ) ) { throw 'Attempt to print non-array value' ; } if ( arr . length < 1 ) { throw 'No columns for array detected' } for ( let prop in arr [ 0 ] ) { if ( arr [ 0 ] . hasOwnProperty ( prop ) ) { schema . push ( prop ) ; colWidths . push ( prop . length >= 1 ? prop . length + 1 : 1 ) ; } } for ( let i = 0 ; i < arr . length ; i ++ ) { let newElt = [ ] ; for ( let j = 0 ; j < schema . length ; j ++ ) { let str = sprint_go ( arr [ i ] [ schema [ j ] ] , { } , 1 ) ; if ( colWidths [ j ] < str . length + 1 ) { colWidths [ j ] = str . length + 1 ; } newElt . push ( str ) ; } outArr . push ( newElt ) ; } let output = '\n' ; for ( let i = 0 ; i < schema . length ; i ++ ) { output += schema [ i ] . padStart ( colWidths [ i ] , ' ' ) ; } output += '\n' ; for ( let i = 0 ; i < outArr . length ; i ++ ) { for ( let j = 0 ; j < schema . length ; j ++ ) { output += outArr [ i ] [ j ] . padStart ( colWidths [ j ] , ' ' ) ; } output += '\n' ; } return output ; }
Returns a string containing a tabular representation of the given array.
Returns a string containing a tabular representation of the given array .