Seeking guidance as I work on defining an 'explode' function. This function is intended to take a string input and insert spaces around all letters except the first and last ones. For example, if we call the function with the string Kristopher
, it should return K r i s t o p h e r
.
This is the code I have written:
function explode(text) {
var spacedString = '';
var max = text.length;
for (var i = 0; i < max; i++) {
spacedString += text[i];
if (i !== (max - 1)) {
spacedString += ' ';
}
}
return spacedString;
}
console.log(explode('Kristopher'));
However, when I run this code, instead of the desired output, which is K r i s t o p h e r
, I am getting back kristopher
. Can anyone assist in identifying my mistake?