Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions exercises/MaxChar/Complete/MaxCharComplete.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,13 @@ public static function get1(string $string): string

return (string) $max;
}

public static function get2(string $string): string
{
$chars = str_split($string);
$count = array_count_values($chars);
arsort($count);

return (string) key($count);
}
}
5 changes: 5 additions & 0 deletions exercises/Palindrome/Complete/PalindromeComplete.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,9 @@ public static function check3(string $string): bool

return false;
}

public static function check4(string $string): bool
{
return strrev($string) === $string;
}
}
15 changes: 15 additions & 0 deletions tests/MaxChar/Complete/MaxCharCompleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,19 @@ public function testGet1MaxCharWithNumbers(): void
{
self::assertSame('2', MaxCharComplete::get1('apple 2202'));
}

public function testGet2SingleMaxChar(): void
{
self::assertSame('a', MaxCharComplete::get2('a'));
}

public function testGet2MaxChar(): void
{
self::assertSame('q', MaxCharComplete::get2('qqweqrty'));
}

public function testGet2MaxCharWithNumbers(): void
{
self::assertSame('2', MaxCharComplete::get2('apple 2202'));
}
}
35 changes: 35 additions & 0 deletions tests/Palindrome/Complete/PalindromeCompleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,39 @@ public function testDeifiedIsAPalindrome3(): void
{
self::assertTrue(PalindromeComplete::check3('deified'));
}

public function testFafIsPalindrome4(): void
{
self::assertTrue(PalindromeComplete::check4('faf'));
}

public function testFafSpaceIsNotAPalindrome4(): void
{
self::assertFalse(PalindromeComplete::check4('faf '));
}

public function testSpaceFafIsNotAPalindrome4(): void
{
self::assertFalse(PalindromeComplete::check4(' faf'));
}

public function testHelloIsNotAPalindrome4(): void
{
self::assertFalse(PalindromeComplete::check4('hello'));
}

public function test11211IsAPalindrome4(): void
{
self::assertTrue(PalindromeComplete::check4('11211'));
}

public function testDogSpaceGodIsNotAPalindrome4(): void
{
self::assertFalse(PalindromeComplete::check4('Dog god'));
}

public function testDeifiedIsAPalindrome4(): void
{
self::assertTrue(PalindromeComplete::check4('deified'));
}
}