Last active
April 8, 2022 08:23
-
-
Save cgcostume/abfb3a9fbfa08a49b8d0db6f02721650 to your computer and use it in GitHub Desktop.
join elements of an array of strings using a ', ' and for the last one use an ' and ', e.g., for a readable author list
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
const happyAnd = (strings) => | |
strings.length === 0 ? '' : strings.reduce((text, value, i, array) => | |
text + (i < array.length - 1 ? ', ' : array.length > 2 ? ', and ' : ' and ') + value); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment