forked from TheAlgorithms/JavaScript
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountVowels.js
More file actions
Latest commit
21 lines (17 loc) · 534 Bytes
/
Copy pathCountVowels.js
File metadata and controls
21 lines (17 loc) · 534 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* @function countVowels
* @description Given a string of words or phrases, count the number of vowels.
* @param {String} str - The input string
* @return {Number} - The number of vowels
* @example countVowels("ABCDE") => 2
* @example countVowels("Hello") => 2
*/
constcountVowels=(str)=>{
if(typeofstr!=='string'){
thrownewTypeError('Input should be a string')
}
constvowelRegex=/[aeiou]/gi
constvowelsArray=str.match(vowelRegex)||[]
returnvowelsArray.length
}
export{countVowels}