let result = []
for (let index = 0, string = 'Hello, World!Привет, Мир!'; index < string.length; index++) {
if (result.length === 0 || !/[a-zа-яЁё]/ig.test(string[index])) {
result.push(string[index])
} else {
result[result.length - 1] = result[result.length - 1] + string[index]
}
}
console.log(result);
const res = [...'Hello, World!Привет, Мир!'].reduce((acc, letter) => {
!acc.length || !/[a-zа-яЁё]/ig.test(letter)
?
acc.push(letter)
:
acc[acc.length - 1] += letter
return acc
}, []);
console.log(res)