Задача
JavaScript testРешение:
function stringExpansion(str) {
const split = str.split('');
let repeated = 1;
let result = [];
if (split.map((item) => +item).every((item) => isNaN(item))) {
return str;
}
if (split.map((item) => +item).every((item) => !isNaN(item))) {
return '';
}
if (split.map((item) => +item).filter((item) => !isNaN(item)).every((item) => item === 0)) {
return '';
}
split.forEach((c) => {
if (!isNaN(c)) {
repeated = c;
}
if (isNaN(c)) {
result.push(c.repeat(repeated));
}
});
return result.join('').length === 0 ? str :result.join('');
}