This commit is contained in:
Oliver Davies 2020-07-12 16:54:11 +01:00
parent fee5c1afe4
commit a62c22030e
4 changed files with 38 additions and 1 deletions

View file

@ -9,6 +9,7 @@ Includes:
- **Bob**: returns different responses based on input.
- **Bowling**: calculate the score for a game of bowling.
- **Grade School**: given students' names along with the grade that they are in, create a roster for the school.
- **Pangram** - determine if a sentence is a pangram (every letter of the alphabet is used at least once).
- **Rock, paper, scissors**
- **Roman numerals**: convert a number into its roman numeral value.

View file

@ -10,7 +10,10 @@
"phpunit/phpunit": "^9.0"
},
"autoload": {
"files": ["src/FlattenArray.php"],
"files": [
"src/FlattenArray.php",
"src/Pangram.php"
],
"psr-4": {
"App\\": "src/"
}

14
src/Pangram.php Normal file
View file

@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace App;
function isPangram(string $input): bool
{
$split = str_split($input);
$lower = array_map('strtolower', $split);
$filtered = array_filter($lower, fn(string $letter) => $letter != ' ');
return count(array_unique($filtered)) == 26;
}

19
tests/PangramTest.php Normal file
View file

@ -0,0 +1,19 @@
<?php
use function App\isPangram;
it('determines if a string is a pangram', function (
string $input,
bool $expected
) {
assertSame($expected, isPangram($input));
})->with([
[
'input' => 'hello word',
'expected' => false,
],
[
'input' => 'The quick brown fox jumps over the lazy dog',
'expected' => true,
]
]);