Created
August 7, 2019 23:07
-
-
Save parzibyte/7044f8778bb5db502d0b51a8005f337e to your computer and use it in GitHub Desktop.
Cadena termina en vocal con JavaScript - https://parzibyte.me/blog/2018/09/25/javascript-comprobar-si-una-cadena-termina-en-vocal/
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
const terminaEnVocal = cadena => { | |
// Si no hay cadena o está vacía... | |
if(!cadena || !cadena.length) return false; | |
// Sacar el último carácter y convertirlo a minúscula | |
let ultimoCaracter = cadena[cadena.length - 1].toLowerCase(); | |
// Con indexOf comprobar si dicho carácter está en el | |
// arreglo ["a", "e", "i", "o", "u"] | |
// Si sí está, indexOf devolverá algo diferente a -1 | |
// Si no está, entonces indexOf devolverá -1 | |
// Con eso ya podemos evaluar y convertirlo a booleano | |
return ["a", "e", "i", "o", "u"].indexOf(ultimoCaracter) !== -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment