Created
June 19, 2013 19:54
-
-
Save cskevint/5817477 to your computer and use it in GitHub Desktop.
Titleize a sentence in JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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