Upon executing the function below, I encountered the following error:
"Error: Possible infinite loop."
The issue appears to stem from the use of "0" in the splice method, as changing it to any other number (1-9) eliminates the error.
I'm uncertain as to how this could result in an infinite loop.
Could it be that the "0" in the splice method is causing confusion with "i" or something else?
Any assistance would be greatly valued, thank you.
function spinalCase(str) {
var array = str.split("");
for (i = 0; i < array.length; i++) {
if (array[i] !== array[i].toLowerCase()) {
array.splice(i, 0, " ");
}
}
return array;
}
spinalCase('AllThe-small Things');