Skip to content

Commit b9474b9

Browse files
authored
feat(Vowels): merge pull request from Ahmed-Aboud
added count3 function to count Vowels and test cases
2 parents 8c61b20 + a88b77a commit b9474b9

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

exercises/Vowels/Complete/VowelsComplete.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,18 @@ public static function count2(string $string): int
3131

3232
return $counter;
3333
}
34+
35+
public static function count3(string $string): int
36+
{
37+
$counter = 0;
38+
$length = strlen($string);
39+
$vowels = ['a','e','i','o','u'];
40+
41+
for($i=0;$i < $length;++$i){
42+
if (in_array(strtolower($string[$i]),$vowels)) {
43+
++$counter;
44+
}
45+
}
46+
return $counter;
47+
}
3448
}

tests/Vowels/Complete/VowelsCompleteTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,20 @@ public function testCanCountNone2(): void
4848
{
4949
self::assertSame(0, VowelsComplete::count2('bcdfghjkl'));
5050
}
51+
public function testCanCount3(): void
52+
{
53+
self::assertSame(5, VowelsComplete::count3('abcdefghijklmnopqrstuvwxyz'));
54+
}
55+
public function testCanCountAllUpper3(): void
56+
{
57+
self::assertSame(5, VowelsComplete::count3('AEIOU'));
58+
}
59+
public function testCanCountOnly3(): void
60+
{
61+
self::assertSame(5, VowelsComplete::count3('aeiou'));
62+
}
63+
public function testCanCountNone3(): void
64+
{
65+
self::assertSame(0, VowelsComplete::count3('bcdfghjkl'));
66+
}
5167
}

0 commit comments

Comments
 (0)