Skip to content

Instantly share code, notes, and snippets.

@lachlan-eagling
Created March 16, 2017 21:50
Show Gist options
  • Save lachlan-eagling/f3da898b0d6a63093c87cb032b8d4be7 to your computer and use it in GitHub Desktop.
Save lachlan-eagling/f3da898b0d6a63093c87cb032b8d4be7 to your computer and use it in GitHub Desktop.
function titleCase(str) {
var words = str.split(" ");
for(var i = 0; i < words.length; i++){
var temp = words[i].split("");
for(var j = 0; j < temp.length; j++){
if(j === 0){
temp[j] = temp[j].toUpperCase();
} else{
temp[j] = temp[j].toLowerCase();
}
}
words[i] = temp.join("");
}
str = words.join(" ");
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment