| Viewed 149 times

Insert White Spaces Between Lower and Uppercase Letters in Javascript


I need a function that inserts a white space between every instance of a lower character followed immediately by an upper character.

1 Answer
Mohammad Qandeel
Answered
23

Ok, you can do it using the following method

function insertWhitespace(s) {
 return s.split("").map((i, index)=>{
  if(index!==0)
   if(i !== i.toLowerCase())
    return " "+i;
  return i;
 }).join("");
}

Example

insertWhitespace('helloInternet') //"hello Internet"



Related Questions