Align a text table
A JavaScript exercise from Scriptdrill. Solve it with a code editor in your browser that runs your function against example and hidden tests, and it is checked the moment you submit.
The task
`rows` is an array of rows, each an array of strings with the same number of cells. Return one line per row: pad every column to its widest cell, with the first column left-aligned and the other columns right-aligned, cells joined by two spaces, and no trailing spaces on any line.
What this exercise teaches
Widths must be known before any line is built, so this takes two passes. padEnd and padStart add spaces up to the width, and trimEnd removes the padding a short last column would otherwise leave behind.
A hint if you get stuck
First work out each column's width with `Math.max` over the rows. Then `padEnd` the first cell, `padStart` the others, `join(" ")` and `trimEnd()`. Think about an empty `rows`.
This exercise is part of Pro
Pro unlocks all 45 exercises, with worked solutions and progress saved to your account. The free exercises work without an account.
You create a free account first, so Pro is attached to it.
Monthly is charged today and then every month until you cancel, in one click from your account page. Lifetime is one payment with no renewals. Full refund within 14 days of paying.