Last active
October 1, 2019 16:16
-
-
Save rchipka/af8ebf11719ac5e36d429f1d64805b93 to your computer and use it in GitHub Desktop.
Concise JavaScript natural language array join sentence
This file contains hidden or 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
| [values.pop(), values.join(', ')].filter(v => v).reverse().join(' and ') | |
| // ['this'] => 'this' | |
| // ['this', 'that'] => 'this and that' | |
| // ['this', 'that', 'the other'] => 'this, that and the other' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment