@@ -28,7 +28,7 @@ const get_negative = (arr, total_cols) => {
28
28
const get_positive = ( arr , total_cols ) => {
29
29
let col_positive = [ ] ;
30
30
for ( let i = 0 ; i < total_cols ; i ++ ) {
31
- let _arr = arrayColumn ( arr , i ) . filter ( r => r > 0 ) ;
31
+ let _arr = arrayColumn ( arr , i ) . filter ( r => r >= 0 ) ;
32
32
let _n = Math . max ( ..._arr ) || 0 ;
33
33
col_positive . push ( _n ) ;
34
34
}
@@ -77,7 +77,6 @@ class Table extends StringUDF {
77
77
//get each col length
78
78
let col_length = JSON . parse ( JSON . stringify ( array ) ) ;
79
79
80
-
81
80
let total_cols = col_length [ 0 ] . length ;
82
81
if ( col_length [ 0 ] . constructor !== Array ) return Promise . reject ( "Input is invalid for table conversion." )
83
82
@@ -98,23 +97,26 @@ class Table extends StringUDF {
98
97
let col_length_arr = col_length . map ( ( r ) => r . map ( ( c ) => lengths ( c , decimalLengths ) ) ) ;
99
98
let col_max = [ ...max_string_lengths ( col_length_arr , total_cols ) ] ;
100
99
100
+ // console.log(col_negative, col_positive, col_length_arr, col_max);
101
+
102
+
101
103
const format_row = ( arrayValue , index ) => {
102
104
var rowTxt = arrayValue ;
105
+
103
106
//check decimal
104
107
if ( decimalLengths > 0 && typeof ( rowTxt ) == 'number' )
105
108
rowTxt = rowTxt . toFixed ( decimalLengths ) ;
106
109
107
- if ( index == total_cols - 1 )
108
- return rowTxt ;
110
+ // if (index == total_cols - 1)
111
+ // return rowTxt;
109
112
110
113
//add_space_if_col_have_negative
111
114
let isNegative = col_negative [ index ] < 0 && rowTxt >= 0 ;
112
115
113
- //add extra space if col have negative and postive length>negative
116
+ //add extra space if col have negative and positive length>negative negative
114
117
let positive_buffer = col_negative [ index ] < 0 && col_max [ index ] >= col_negative [ index ] . toString ( ) . length && col_positive [ index ] . toString ( ) . length >= col_negative [ index ] . toString ( ) . length
115
118
116
- var _spaces = ( - isNegative + positive_buffer + col_max [ index ] - lengths ( rowTxt , decimalLengths ) ) || 0 ;
117
- _spaces = _spaces < 0 ? 0 : _spaces ;
119
+ var _spaces = Math . max ( 0 , ( ( - isNegative + positive_buffer + col_max [ index ] - lengths ( rowTxt , decimalLengths ) ) || 0 ) ) ;
118
120
let _txt = rowTxt + rpt ( _spaces ) ;
119
121
120
122
let _return = isNegative ? rpt ( 1 ) + _txt : _txt ;
0 commit comments