Here is the link of this challenge:https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-algorithm-scripting/title-case-a-sentence
my result is the same as the answer but why this hapeen. Anyone Explain for me please.
here is my code:
function titleCase(str) {
// let arr = [];
str=str.toLowerCase();
str=" "+str+" ";
let rel="";
// let a=/a/i,
// the=/the/i;
for (let i = 0 , l = str.length, se="" ; i < l ; i ++) {
if (str[i]==" ") {
//arr.push(se);
// console.log(se);
// console.log(se);
if ((se=="a" ) || (se=="The")) {
se = se.toUpperCase();
// console.log(se);
}
rel+=se+" ";
se="";
if (i!==l-1) se += str[i+1].toUpperCase();
continue;
}
if (str[i-1]!==" ")se += str[i].toLowerCase();
}
return rel.slice(1,rel.length-1);
//return rel-" ";
}
console.log(titleCase("I'm a little tea pot the"));
let a='f';
//console.log(ASCI);


