Created
January 30, 2019 13:25
-
-
Save edvaldoszy/9073661da00484632259135f10705aa5 to your computer and use it in GitHub Desktop.
Função para abreviar nomes grandes
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
| function abrevia(str) { | |
| const nome = str.replace(/\s+/gi, ' ') | |
| .trim(); | |
| return nome.split(' ') | |
| .map((parte, index, nomes) => (index == (nomes.length - 1)) ? parte : `${parte[0]}.`) | |
| .join(' '); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Olá, o ideal seria:
Sendo assim ele vai poder abreviar somente o primeiro nome.