Created
October 24, 2018 21:14
-
-
Save adamcrampton/0cb4eb78f1a2de9fe1c489f3a6f8ec4d to your computer and use it in GitHub Desktop.
Takes a comma separated string and replaces the last comma with ", and"
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
commaStringFormatter = (speechArray) => { | |
formattedString = [speechArray.slice(0, -1).join(', '), speechArray.slice(-1)[0]].join(speechArray.length < 2 ? '' : ', and '); | |
return formattedString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment