Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created August 7, 2019 20:57
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/cfec36867bce98df95b3157243e94995 to your computer and use it in GitHub Desktop.
Save parzibyte/cfec36867bce98df95b3157243e94995 to your computer and use it in GitHub Desktop.
const comienzaConVocal = (cadena) => {
if (!cadena || cadena.length <= 0) return false;
// Convertir a minúscula porque las vocales con las que la compararemos están
// en minúscula
let cadenaEnMinuscula = cadena.toLowerCase();
let primerCaracter = cadenaEnMinuscula.charAt(0);
// Vamos a buscar si el carácter está en este arreglo
const vocales = ["a", "e", "i", "o", "u"];
// indexOf devuelve -1 si no encuentra el carácter en el arreglo
// y si lo encuentra, devuelve el índice o posición, pero eso no nos importa ahora
if (vocales.indexOf(primerCaracter) === -1) {
return false;
} else {
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment