Skip to content

Commit 78166af

Browse files
authored
Create VowelCount.lua
1 parent de5f50c commit 78166af

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

strings/VowelCount.lua

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
end
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

Comments
 (0)