I'm wondering if there is an elegant solution for undoing this string manipulation:
'hello world'.split('').join(' '); // result: 'h e l l o w o r l d'
My current solution is not elegant as the code that inserts spaces (the above code), in my opinion. It do work but can I do better?
let spaces = 'h e l l o w o r l d'.split(' ');
let r = '';
for (let i = 0, len = spaces.length; i < len; ++i) {
r += spaces[i].split(' ').join('');
if (i != len - 1) {
r += ' ';
}
}