Last active
March 10, 2025 21:19
-
-
Save aaronbeall/d8ba94962d260753b88472c96f80ef08 to your computer and use it in GitHub Desktop.
printTable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const printTable = data => { | |
const header = data[0] | |
const columnWidths = header.map((_, column) => | |
Math.max(...data.map(row => `${ row[column] }`.length)) | |
); | |
const pad = (text, length) => `${ text }${ new Array(length - text.length + 1).join(" ") }` | |
data.forEach(row => { | |
console.log(row.map((column, i) => pad(column, columnWidths[i])).join(" | ")) | |
}) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment