Сообщение от NovichokJS
|
if (newStr.length < len) {
|
let n = str.length % len;
str = str.padEnd(n + str.length, dot);
const splitText = (str, len = 10, dot = '*') => {
if (typeof str !== 'string') {
return null;
}
let n = str.length % len;
str = str.padEnd(n + str.length, dot);
let txt = '';
for (let i = 0; i < str.length; i++) {
let k = i % len, e = str[i];
txt += k == 0 ? e.toUpperCase() : k == len - 1 ? `${e}\n` : e
}
return txt;
}
console.log(splitText('abcdefghijklmn', 4));
/* Abcd
Efgh
Ijkl
Mn**
*/