585.Count Vowels and Consonants in a String
Easy
Given a string
text, return [vowels, consonants]: how many letters are vowels (a, e, i, o, u, in either case) and how many letters are consonants. Characters that are not letters are not counted.
Two details make this more than a simple loop. Letters come in two casesLetter CaseUpper case (A–Z) and lower case (a–z) versions of the same letters, stored as different character codes., so "E" and "e" must be treated alike; and only letters belong to either group. A lookup stringLookup StringA short string listing the allowed characters, used with indexOf / in / includes to test membership. such as "aeiouAEIOU" handles the first point in one test.
Example 1:
Input: text = "Hello World"
Output: [3,7]
Example 2:
Input: text = "2 + 2"
Output: [0,0]
+ 4 hidden test cases run on Submit.
Constraints:
- ●
1 ≤ text.length ≤ 200 - ●
text contains printable ASCII characters
text =
Hello World