Created
June 30, 2020 19:21
-
-
Save andreiskandar/c4c2085eb115dc9fe763cfaa4055e07e to your computer and use it in GitHub Desktop.
Countiny number of vowels that appear in a given string
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
/* | |
In this exercise, we will be counting the number of vowels that appear in a given string. For this exercise, consider the following to be vowels: a, e, i, o, and u. | |
INPUT | |
const numberOfVowels = function(data) { | |
// Put your solution here | |
}; | |
console.log(numberOfVowels("orange")); //3 | |
console.log(numberOfVowels("lighthouse labs")); //5 | |
console.log(numberOfVowels("aeiou")); //5 | |
*/ | |
const numberOfVowels = function(data) { | |
let regex = 'aeiou'; | |
let count = 0; | |
for(let i = 0; i < data.length; i++){ | |
if(regex.indexOf(data[i]) >= 0) count++; | |
} | |
return count; | |
}; | |
console.log(numberOfVowels("orange")); | |
console.log(numberOfVowels("lighthouse labs")); | |
console.log(numberOfVowels("aeiou")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment