Last active
February 22, 2020 16:38
-
-
Save brenofreire/637ea68699bfba9a154ae9027206de42 to your computer and use it in GitHub Desktop.
Retorna uma string capitalizada
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
// O método map retorna um valor mapeado pro array original. | |
// Ou seja nesse caso, ele retorna a string obedecendo aquela regra. | |
// Vale lembrar que o uso dos objeto global de string nesse caso é bem inteligente. | |
String.prototype.toCapitalize = () => { | |
return this.split(" ").map(word => { | |
return word.charAt(0).toUpperCase() + word.slice(1); | |
}).join(" "); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment