Last active
September 30, 2016 15:59
-
-
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++
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
// 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