Skip to content

Instantly share code, notes, and snippets.

@hassanuos
Created June 11, 2024 04:51
Show Gist options
  • Save hassanuos/adf44bc01eeab28a2657a52b03712e23 to your computer and use it in GitHub Desktop.
Save hassanuos/adf44bc01eeab28a2657a52b03712e23 to your computer and use it in GitHub Desktop.
count vowels in the string
const str = "Hey JS! You R AMAZING";
const vowels = ["a", "e", "i", "o", "u"];
function countVowels(data){
let count = 0;
data.toLowerCase().split("").forEach((ch) => { vowels.includes(ch) && count++;})
return count;
}
const numberOfVowels = countVowels(str);
console.log(numberOfVowels);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment