MCPcopy Create free account
hub / github.com/TheAlgorithms/JavaScript / countVowels

Function countVowels

String/CountVowels.js:10–19  ·  view source on GitHub ↗
(str)

Source from the content-addressed store, hash-verified

8 */
9
10const countVowels = (str) => {
11 if (typeof str !== 'string') {
12 throw new TypeError('Input should be a string')
13 }
14
15 const vowelRegex = /[aeiou]/gi
16 const vowelsArray = str.match(vowelRegex) || []
17
18 return vowelsArray.length
19}
20
21export { countVowels }

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected