Is Underscore(_) Uppercase and so are other special character?


#1

Hi,

I am trying to solve - https://www.freecodecamp.org/challenges/spinal-tap-case, now it seemed easy till i realise that even underscore is treated as upper case , not only that all character like * etc are also upper case , how can i over come this , this is my current code - It is just the start logic but the fact that _ is also upper case is making me confused …


function spinalCase(str) {
    var newStr = str.split("");
   
   
    for(var i = 0; i < newStr.length; i++){
       if(newStr[i] === newStr[i].toUpperCase()&& i !== 0){
           
               console.log(i);
           
           
       }
    }
 //    newStr = newStr.join("");
 //    console.log(newStr);   
       
}
spinalCase("The_Andy_Griffith_Show");
//spinalCase("This Is Spinal Tap");
//spinalCase("thisIsSpinalTap")

;


#2

Ok , i solved it -


function spinalCase(str) {
  
   var newStr = str.split("");
    var  res = [];
    for(var i = 0; i < newStr.length; i++){
       if(newStr[i] === "-"){
            
        }
      
        else if(newStr[i] === "_" || newStr[i] === " "){
            res = newStr.splice(i,1,"-");
        }
        else if(newStr[i] === newStr[i].toLocaleUpperCase() && i !==0 && newStr[i-1] !== "-"){
            res = newStr.splice(i,1,"-" + newStr[i].toLowerCase());
        }
    }
    
   newStr = newStr.join(""); 
   return newStr.toLocaleLowerCase();
       
}

spinalCase("AllThe-small Things");