Skip to content

Instantly share code, notes, and snippets.

@wengzilla
Created July 11, 2012 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wengzilla/3090736 to your computer and use it in GitHub Desktop.
Save wengzilla/3090736 to your computer and use it in GitHub Desktop.
titlelize.js - wengzilla
String.prototype.titleize = function() {
var words = this.split(" ")
var word_count = words.length
for(var i = 0; i < word_count; i++)
if(i == 0 || !is_article(words[i]))
words[i] = words[i].capitalize()
return words.join(" ");
}
String.prototype.capitalize = function() {
var word = this;
if (word[0] && word.toUpperCase)
return word[0].toUpperCase() + word.slice(1);
}
function is_article(word) {
return (word == "a" || word == "an") ? true : false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment