Align columns: Difference between revisions

Simpler D code
(Removed a bug from D code)
(Simpler D code)
Line 633:
 
auto P = array(map!q{ a.chomp("$").split("$") }(splitlines(T)));
auto nCols = reduce!max(map!q{ a.length }(P));
 
int[int] maxWidths;
auto maxWidthCol = new size_t[nCols];
foreach (line; P)
foreach (i, word; line)
maxWidthColmaxWidths[i] = max(maxWidthCol[maxWidths.get(i], 0), word.length);
 
foreach (i, justify; [&ljustify!string, &center!string,
Line 646 ⟶ 645:
foreach (line; P) {
foreach (j, word; line)
write(justify(word, maxWidthColmaxWidths[j]), " ");
writeln();
}
Anonymous user