Even today, with proportional fonts and complex layouts, there are still cases where you need to wrap text at a specified column. The basic task is to wrap a paragraph of text in a simple way. Example text:
Wrap text using a more sophisticated algorithm such as the Knuth and Plass TeX algorithm. If your language provides this, you get easy extra credit, but you "must reference documentation" indicating that the algorithm is something better than a simple minimimum length algorithm.
Task: Write a function that can wrap this text to any number of characters. As an example, the text wrapped to 80 characters should look like the following:
Wrap text using a more sophisticated algorithm such as the Knuth and Plass TeX algorithm. If your language provides this, you get easy extra credit, but you must reference documentation indicating that the algorithm is something better than a simple minimimum length algorithm.
wrap
function should return our expected text
testString: 'assert.equal(wrapped80.split("\n")[0], firstRow80, "Your wrap
function should return our expected text");'
- text: wrap(42) must return 7 lines.
testString: 'assert(wrapped42.split("\n").length === 7, "wrap(42) must return 7 lines.");'
- text: Your wrap
function should return our expected text
testString: 'assert.equal(wrapped42.split("\n")[0], firstRow42, "Your wrap
function should return our expected text");'
```