Skip to content

Instantly share code, notes, and snippets.

@jimjam88
Created August 1, 2022 07:54
Show Gist options
  • Save jimjam88/d6ddcf7a2b9762d1331aa4ad017c50ba to your computer and use it in GitHub Desktop.
Save jimjam88/d6ddcf7a2b9762d1331aa4ad017c50ba to your computer and use it in GitHub Desktop.
Punctuation helper
const punctuate = (items = []) => {
const amount = items.length;
return items.reduce((acc, item, index) => {
if (amount === 1) {
return item;
}
return index === (amount - 1)
? `${acc} and ${item}`
: `${acc}, ${item}`;
}, '');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment