My function is supposed to separate a camel-cased string (e.g. "camelCase" into "camel Case"). My logic is basically that I split the string into an array, identify uppercase characters, and then splice in a space character before the uppercase character. Returning a joined array. I could figure out a different solution but, I more curious about why my function isn't returning anything.
My function:
function solution(str) {
let splitStr = str.split("");
for(let i=0; i<splitStr.length; i++){
if(splitStr[i]===splitStr[i].toUpperCase()){
splitStr.splice(i, 0, " ");
}
}
return splitStr.join("");
}
I would understand if this threw an error but, it doesn't return anything. Not "undefined" or "null", just nothing. So I'm not so much looking for a solution to this challenge as I am curious about why this function spits out nothing. Any help is appreciated!