Skip to content

Instantly share code, notes, and snippets.

@sbrmnn
Created July 1, 2015 15:30
Show Gist options
  • Save sbrmnn/3045d667a9f0c19f4a5b to your computer and use it in GitHub Desktop.
Save sbrmnn/3045d667a9f0c19f4a5b to your computer and use it in GitHub Desktop.
Ruby Titleize for Javascript.
String.prototype.titleize = function() {
var words = this.replace(/_/g, ' ').split(' ')
var array = []
for (var i = 0; i < words.length; ++i) {
array.push(words[i].charAt(0).toUpperCase() + words[i].toLowerCase().slice(1))
}
return array.join(' ');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment