Created
July 1, 2015 15:30
-
-
Save sbrmnn/3045d667a9f0c19f4a5b to your computer and use it in GitHub Desktop.
Ruby Titleize for 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
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