Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created August 7, 2019 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/7044f8778bb5db502d0b51a8005f337e to your computer and use it in GitHub Desktop.
Save parzibyte/7044f8778bb5db502d0b51a8005f337e to your computer and use it in GitHub Desktop.
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