-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountVowels.js
More file actions
25 lines (22 loc) · 791 Bytes
/
countVowels.js
File metadata and controls
25 lines (22 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Create a function that takes a string and returns the number (count) of vowels contained within it.
// Examples:
// countVowels("Celebration") ➞ 5
// countVowels("Palm") ➞ 1
// countVowels("Prediction") ➞ 4
// Notes:
// a, e, i, o, u are considered vowels (not y).
// All test cases are one word and only contain letters.
// function countVowels(str) {
// return str.match(/[aeiou]/g).length;
// }
// console.log(countVowels("Celebration"));
// console.log(countVowels("Palm"));
// Method 2
// const countVowels = (str) => {
// return str.split("").filter((x) => "aeiouAEIOU".includes(x).length);
// };
// console.log(countVowels("aabc"));
function countVowels(str) {
return str.split("").filter((x) => "aeiouAEIOU".includes(x)).length;
}
console.log(countVowels("aabc"));