Skip to content

Commit 2a4faa5

Browse files
committed
12 - Vowel Count.js
1 parent 8bca0e3 commit 2a4faa5

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

12 - Vowel Count.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Step By Step
2+
function VowelCount (str) {
3+
// First, we Remove all characters in the string that aren't vowels with the .replace method.
4+
// Note that ^ in Regex means "all characters not in the set", so placing it in front of aeiou means "Match everything that isn't a vowel"
5+
// Enclosing a set in [] means that our string matches any individual character in that set
6+
// Ending with our /g tag signifies that we want to do a global search and lets our engine know to going through the entire string.
7+
str = str.replace(/[^aeiuo]/g, '');
8+
9+
// Finally, we return the length of the string to "count" how many vowels are left.
10+
return str.length;
11+
}
12+
13+
14+
// No Comments
15+
function VowelCount (str) {
16+
return str.replace(/[^aeiou]/g, '').length;
17+
}

0 commit comments

Comments
 (0)