Skip to content

Instantly share code, notes, and snippets.

@codeangler
Last active September 30, 2016 15:59
Show Gist options
  • Save codeangler/e7e9b3de2e27ebaa62011c7ae3960e83 to your computer and use it in GitHub Desktop.
Save codeangler/e7e9b3de2e27ebaa62011c7ae3960e83 to your computer and use it in GitHub Desktop.
prefix incrementor vs postfix incrementor is critical for this to work ++prev != prev++
// 7. Write a JavaScript function that accepts a string as a parameter and counts the number of vowels within the string. Go to the editor
// Note : As the letter 'y' can be regarded as both a vowel and a consonant, we do not count 'y' as vowel here.
// Example string : 'The quick brown fox'
// Expected Output : 5
((str) => console.log(
str.split('')
.reduce(
(prev, current) => {
if("aeiouAEIOU".split('').indexOf(current) != -1){
return ++prev;
} else{
return prev
};
},0 )
))("The quick brown fox");
// NOTE: prefix incrementor vs postfix incrementor is critical for this to work ++prev != prev++
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment