Last active
May 1, 2018 05:41
-
-
Save Luke-Rogerson/f74bbc2c6f335ef737c85df79571e10d to your computer and use it in GitHub Desktop.
VowelCount algorithm challenge created by Luke_Rogerson - https://repl.it/@Luke_Rogerson/VowelCount
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
/* | |
Vowel Count * | |
* Using the JavaScript language, have the function VowelCount(str) take the str * | |
* string parameter being passed and return the number of vowels the string contains * | |
* (ie. "All cows eat grass" would return 5). Do not count y as a vowel for this * | |
* challenge. | |
*/ | |
// Split sentence into array | |
// | |
function VowelCount(str) { | |
var strArray = str.toLowerCase().split(' '); | |
var total = 0; | |
for (let i = 0; i < strArray.length; i++) { | |
for (let j = 0; j < strArray[i].length; j++) { | |
if ( | |
strArray[i][j] === 'a' || | |
strArray[i][j] === 'e' || | |
strArray[i][j] === 'i' || | |
strArray[i][j] === 'o' || | |
strArray[i][j] === 'u' | |
) { | |
total += 1; | |
} | |
} | |
} | |
return total; | |
} | |
VowelCount('The cat sat on the mat.'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment