Skip to content

Instantly share code, notes, and snippets.

@adamcrampton
Created October 24, 2018 21:14
Show Gist options
  • Save adamcrampton/0cb4eb78f1a2de9fe1c489f3a6f8ec4d to your computer and use it in GitHub Desktop.
Save adamcrampton/0cb4eb78f1a2de9fe1c489f3a6f8ec4d to your computer and use it in GitHub Desktop.
Takes a comma separated string and replaces the last comma with ", and"
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