Skip to content

Instantly share code, notes, and snippets.

@SauloSilva
Created January 25, 2014 20:36
Show Gist options
  • Save SauloSilva/8623205 to your computer and use it in GitHub Desktop.
Save SauloSilva/8623205 to your computer and use it in GitHub Desktop.
Clone to setence active support of rails.
Array.prototype.toSentence = ->
wordsConnector = ', '
lastWordConnector = ' e '
sentence = undefined
switch @length
when 0
sentence = ''
when 1
sentence = @[0]
when 2
sentence = @[0] + lastWordConnector + @[1]
else
sentence = @slice(0, -1).join(wordsConnector) + lastWordConnector + @[@length - 1]
sentence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment