Tell us what’s happening:
Describe your issue in detail here.
**Your code so far**
function titleCase(str) {
str=str.toLowerCase();
let reg = /(\S+)/g;
let a=str.match(reg);
let b=[];
//console.log(a);
let s="";
for(let i=0;i<a.length;i++){
b[i]=[];
for(let j=0;j<a[i].length;j++){
b[i].push(a[i][j]);
b[i][0]=b[i][0].toUpperCase();
s+=b[i][j];
}
s+=" ";
}
console.log(s);
//console.log(str);
//console.log(b)
return s;
}
titleCase("I'm a little tea pot");
console.log("I'm A Little Tea Pot");
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 OPR/76.0.4017.154
Some parts are a bit more complicated than they could be. For example splitting sentence with regex, while it could be achieved with simple string method. Or b[i][0]=b[i][0].toUpperCase();, which is being run multiple times while iterating over letters in the same word.
Readability would be also improved with using better variable names, rather than single letters.
Having all that said, first step is really making it work, after that there’s time to look closer where code can be improved or simplified.