Skip to content

Instantly share code, notes, and snippets.

@cskevint
Created June 19, 2013 19:54
Show Gist options
  • Save cskevint/5817477 to your computer and use it in GitHub Desktop.
Save cskevint/5817477 to your computer and use it in GitHub Desktop.
Titleize a sentence in JavaScript
function titleize(sentence) {
if(!sentence.split) return sentence;
var _titleizeWord = function(string) {
return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
},
result = [];
sentence.split(" ").forEach(function(w) {
result.push(_titleizeWord(w));
});
return result.join(" ");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment