You write a class called Wrapper, that has a single static function named wrap that takes two arguments, a string, and a column number. The function returns the string, but with line breaks inserted at just the right places to make sure that no line is longer than the column number. You try to break lines at word boundaries. Like a word processor, break the line by replacing the last space in a line with a newline.
- it takes two arguments: a string text to split in a way that there would be no lines longer than the number columns
- returns the original string with this new format
- Return null when the column parameter is not a positive integer
- Split at the last space character before reaching the given column
- Split at the given column number when there is no space before
- do not copy spaces at the first or last position of each line
var Wrapper = require('./src/wrapper.js');
//...
var splitThis = new Wrapper().wrap('0123456789', 5);
calling splitThis
will return:
01234\n56789
MIT