Last active
October 29, 2018 17:45
-
-
Save Papacidero/65646c51090ef76c3c6ceaf1d400aebf to your computer and use it in GitHub Desktop.
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
// Sem Named Parameters | |
const formatarData = (dia, mes, ano, formato) => { | |
return `${ | |
formato | |
.replace('dia', dia) | |
.replace('mes', mes) | |
.replace('ano', ano) | |
}` | |
} | |
// Transformando a data no formato americano: | |
formatarData(10, 8, 1982, 'ano/mes/dia'); // Resultado: 1982/8/10 | |
// Invertendo os argumentos ao passar como formato Americano (Ano, Mês, Dia) | |
formatarData(1982, 10, 8, 'ano/mes/dia'); // Resultado errado: 8/10/1982 | |
// Esquecendo de passar algum parametro | |
formatarData(10, 8, 'dia/mes/ano'); // Resultado: Cannot read property 'replace' of undefined | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment