Returns a string, making sure the first letter of each word in the string is capitalized and the rest is lowercase.
The same goes for connectors like 'the' and 'of'.
function titleCase(str) {
// Convert all letters of the string to lowercase and convert them to character arrays according to spaces
var arr = str.toLowerCase().split(" ");
// Traverse the character array
for(var i = 0;i < arr.length;i++){
//Change the first character to uppercase
arr[i] = arr[i][0].toUpperCase() + arr[i].substring(1,arr[i ].length);
}
//Add spaces to return the original pattern string
return arr.join(" ");
}