Skip to content

Instantly share code, notes, and snippets.

@aaronbeall
Last active March 10, 2025 21:19
Show Gist options
  • Save aaronbeall/d8ba94962d260753b88472c96f80ef08 to your computer and use it in GitHub Desktop.
Save aaronbeall/d8ba94962d260753b88472c96f80ef08 to your computer and use it in GitHub Desktop.
printTable
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