Ejemplo 1: contar vocales en javascript
const vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'];
function countVowels(sentence) {
let counts = 0;
for(let i = 0; i < vowels.length; i++) {
if(vowels.includes(sentence[i])) {
counts++;
}
}
return console.log(counts);
}
countVowels('Hello World');
countVowels('AaEeIiOoUu');
countVowels('aaaaa');
Ejemplo 2: verificación de vocales en javascript
// check the word is vowel or not
let words = "aeiou";
let newWords = "";
function isVowelOrNot(words) {
for (let word of words) {
if (
word === "a" ||
word === "e" ||
word === "i" ||
word === "o" ||
word === "u"
) {
newWords = newWords + word;
}
}
if (newWords === words) {
return true;
} else {
return false;
}
}
let result = isVowelOrNot(words);
console.log(result);
Ejemplo 3: contar vocales en una cadena javascript
// BEST and FASTER implementation using regex
const countVowels = (str) => (str.match(/[aeiou]/gi) || []).length
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)