Skip to content

Instantly share code, notes, and snippets.

@brenofreire
Last active February 22, 2020 16:38
Show Gist options
  • Save brenofreire/637ea68699bfba9a154ae9027206de42 to your computer and use it in GitHub Desktop.
Save brenofreire/637ea68699bfba9a154ae9027206de42 to your computer and use it in GitHub Desktop.
Retorna uma string capitalizada
// 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