We are building a word processor and we would like to implement a "reflow" functionality that also applies full justification to the text.
Given an array containing lines of text and a new maximum width, re-flow the text to fit the new width. Each line should have the exact specified width. If any line is too short, insert '-' (as stand-ins for spaces) between words as equally as possible until it fits.
Note: we are using '-' instead of spaces between words to make testing and visual verification of the results easier.
lines = [ "The day began as still as the", "night abruptly lighted with", "brilliant flame" ] reflowAndJustify(lines, 24) ... "reflow lines and justify to length 24" => [ "The--day--began-as-still", "as--the--night--abruptly", "lighted--with--brilliant", "flame" ] // <--- a single word on a line is not padded with spaces |