scripts/bit-lib.js
/**
 *  Print an Array of items, where each item is an Array of strings. Typically each item is a narrow multiline status report about a server.
 * @param {string[][]} items - A list of items to print.
 * @param {number} n - number of columns to print in
 * @param {Function} printfn - what print function to use. Typically ns.print or ns.tprint.
 */
Print an Array of items, where each item is an Array of strings. Typically each item is a narrow multiline status report about a server.
@param {string[][]} items - A list of items to print.
@param {number} n - number of columns to print in
@param {Function} printfn - what print function to use.
Print an Array of items where each item is an Array of strings . Typically each item is a narrow multiline status report about a server . @param { string [] [] } items - A list of items to print . @param { number } n - number of columns to print in @param { Function } printfn - what print function to use .
function printItemsNColumns(items, n, printfn) {
    if (items.length === 0) return;
    if (items.length === 1 && items[0].length === 0) return;
    let columns = splitNWays(items, n);
    let rows = columns[0].map((_, colIndex) => columns.map((row) => row[colIndex]));
    for (const row of rows) {
        let numrows = 0;
        try {
            numrows = Math.max(...row.map((item) => item.length));
        } catch {
        }
        for (let i = 0; i < numrows; i++) {
            let line = row.map((item) => {
                if (item && item.length > i) return item[i];
                else return Array(item[0].length + 1).join(' ');
            });
            printfn(line.join('   '));
        }
    }
}
function printItemsNColumns ( items , n , printfn ) { if ( items . length === 0 ) return ; if ( items . length === 1 && items [ 0 ] . length === 0 ) return ; let columns = splitNWays ( items , n ) ; let rows = columns [ 0 ] . map ( ( _ , colIndex ) => columns . map ( ( row ) => row [ colIndex ] ) ) ; for ( const row of rows ) { let numrows = 0 ; try { numrows = Math . max ( ... row . map ( ( item ) => item . length ) ) ; } catch { } for ( let i = 0 ; i < numrows ; i ++ ) { let line = row . map ( ( item ) => { if ( item && item . length > i ) return item [ i ] ; else return Array ( item [ 0 ] . length + 1 ) . join ( ' ' ) ; } ) ; printfn ( line . join ( '   ' ) ) ; } } }
Print an Array of items, where each item is an Array of strings.
Print an Array of items where each item is an Array of strings .
/** @type{string[][][]} */ // Now columns[0] is is a list of items to print in column 0, etc. // Since we want to print by rows, let's transpose the array // row is now an Array of n items, with each item being an Array of strings to print. /*pass*/ // line is now an Array of strings, which just need to be joined and printed.