-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay13.js
More file actions
23 lines (20 loc) · 813 Bytes
/
Day13.js
File metadata and controls
23 lines (20 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// 13: Write a function that takes a string as input and returns the count of vowels in that string. Consider 'a', 'e', 'i', 'o', and 'u' as vowels (both lowercase and uppercase).
const countVowels = (str) => {
let vowels = ["a", "e", "i", "o", "u"];
let arr = str.split("");
// console.log(arr);
let count = 0;
for (let char of arr) {
if (vowels.includes(char.toLowerCase())) {
count++;
}
}
return count;
};
// Example usage:
console.log(countVowels("Helloo world")); // Output: 4
console.log(countVowels("ThE quIck brOwn fOx")); // Output: 5
console.log(countVowels("Brrrp")); // Output: 0
// Constraints:
// The input string may contain letters in both uppercase and lowercase.
// The output should be a non-negative integer representing the count of vowels in the input string.