21 lines
425 B
JavaScript
21 lines
425 B
JavaScript
|
'use strict';
|
||
|
|
||
|
module.exports = input => {
|
||
|
if (typeof input !== 'string') {
|
||
|
throw new TypeError(`Expected input to be a string, got ${typeof input}`);
|
||
|
}
|
||
|
|
||
|
const lines = input.split('\n');
|
||
|
const maxLength = Math.max.apply(null, lines.map(line => line.length));
|
||
|
|
||
|
return lines
|
||
|
.map(line => {
|
||
|
if (line.length < maxLength) {
|
||
|
line += ' '.repeat(maxLength - line.length);
|
||
|
}
|
||
|
|
||
|
return line;
|
||
|
})
|
||
|
.join('\n');
|
||
|
};
|