We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent de5f50c commit 78166afCopy full SHA for 78166af
strings/VowelCount.lua
@@ -0,0 +1,23 @@
1
+-- Author: JoshSCF
2
+-- Returns the amount of vowels in a string
3
+
4
+local Vowels = {
5
+ A = true,
6
+ E = true,
7
+ I = true,
8
+ O = true,
9
+ U = true
10
+}
11
12
+function GetVowelCount(String)
13
+ local Count = 0
14
+ for i = 1, #String do -- Iterate from 1 to the length of string
15
+ local Char = String:sub(i, i) -- Get character at the ith position
16
+ if Vowels[Char:upper()] then -- Check if uppercase form of character is in vowels table
17
+ Count = Count + 1 -- Add one to count
18
+ end
19
20
+ return Count -- Return total amount of vowels found within string
21
+end
22
23
+print(GetVowelCount("Hello, this is an example!")) -- Returns 8
0 commit comments