Skip to content

Instantly share code, notes, and snippets.

@MikeSilvis
Forked from chrismanderson/gist:3090735
Created July 11, 2012 14:31
Show Gist options
  • Save MikeSilvis/3090737 to your computer and use it in GitHub Desktop.
Save MikeSilvis/3090737 to your computer and use it in GitHub Desktop.
Titleize.coffee
String::titleize = ->
titleized = this.split(" ")
UNCAPITALIZED = ['a', 'an']
titleized = (
for word, index in titleized
if word and word.toUpperCase
if word in UNCAPITALIZED && index != 0
word
else
word[0].toUpperCase() + word.slice(1)
)
titleized.join(" ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment