Last active
December 27, 2019 19:43
-
-
Save leonardokl/6f6bf8012773bce96c4d034a094efdf3 to your computer and use it in GitHub Desktop.
Format Text 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
export const formatList = list => | |
list.reduce((acc, text, index) => { | |
if (index === 0) return text; | |
return acc.concat(`${!list[index + 1] ? ' and' : ','} ${text}`); | |
}, ''); |
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
import { formatList } from './formatList'; | |
formatList(['Me', 'myself', 'I']); | |
// Me, myself and I |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment