-
-
Save nchapman/1862601 to your computer and use it in GitHub Desktop.
CoffeeScript version of ActiveSupport's to_sentence method.
This file contains hidden or 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
toSentence = (array = [], wordsConnector = ", ", twoWordsConnector = " and ", lastWordConnector = ", and ") -> | |
switch array.length | |
when 0 then "" | |
when 1 then array[0] | |
when 2 then array[0] + twoWordsConnector + array[1] | |
else array.slice(0, -1).join(wordsConnector) + lastWordConnector + array[array.length - 1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
+1 Thanks Nick.