For example, for the input "there is a newbie", the output should be "There Is A Newbie".
function titleCase(str) {
let arr = str.toLowerCase().split(" ");
let secondArr = [];
for (let i = 0; i<arr.length; i++) {
let subArr = [];
for (let j = 0; j<arr[i].length; j++) {
if (**arr[i][0] == arr[i][j]**) { // I need this condition to be corrected, so that whenever it runs first letter of a word, it makes it the upper case.
subArr.push(arr[i][j].toUpperCase());
} else {
subArr.push(arr[i][j].toLowerCase());
}
}
secondArr.push(subArr.join(""));
}
return secondArr.join(" ");
}
titleCase("You are a little newbie"); // it has to return "You Are A Little Newbie"