Pangram
This commit is contained in:
parent
fee5c1afe4
commit
a62c22030e
|
@ -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.
|
||||
|
||||
|
|
|
@ -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
14
src/Pangram.php
Normal 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
19
tests/PangramTest.php
Normal 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,
|
||||
]
|
||||
]);
|
Loading…
Reference in a new issue