I have been attempting to use the JavaScript splice method to insert a "-" before each capital letter in my array, but it doesn't seem to be working as I expected. I'm not sure where I am going wrong. Below is the code that I have written:
function spinalCase(str) {
let strArr = [];
for(let i = 0; i < str.length; i++){
strArr.push(str[i]);
}
for(let i = 0; i < strArr.length; i++){
if(strArr[i] !== strArr[i].toLowerCase()){
strArr.splice(strArr.indexOf(strArr[i]),0, "-");
}
}
console.log(strArr);
}
spinalCase('thisIsSpinalTap');