Count the Vowels
In this challenge, you are required to write a function that counts the number of vowels ("a, e, i, o, u") in a given sentence.\
Vowels are an essential part of text analysis and are used in many language processing applications, such as readability analysis and phonetic matchin\
To successfully complete the task, your function should handle the following considerations:
Handling Punctuation
The sentence may contain punctuation marks such as periods (.), commas (,), exclamation marks (!), question marks (?), colons (:), and semicolons (;).
Your solution should ignore these punctuation marks and consider only the vowels.
Case Sensitivity
The function should count vowels regardless of their case. Both uppercase and lowercase vowels should be considered the same.
Example Usage
countVowels("Hello World"); // ➞ 3countVowels("I love JavaScript!"); // ➞ 7countVowels("xyz"); // ➞ 0countVowels("AEIOU aeiou"); // ➞ 10
Constraints
- The input will always be a string.
- The string may contain spaces, punctuation, and numbers.
- The function should return an integer.
Hint
Consider using the
method to simplify the comparison, and check for vowels using a loop or a regular expression..toLowerCase()
Function Signature:
/*** @param {string} sentence - The sentence to count vowels in.\* @returns {number} - The number of vowels in the sentence.\*/function countVowels(sentence) {// Your code goes here\}
Did you know?
TypeScript is not a language, it is a superset of JavaScript.
Test Cases
Input:
"Hello World"
Expected Output:
3