Skip to content

Commit

Permalink
Use array_intersect to validate colors in code
Browse files Browse the repository at this point in the history
  • Loading branch information
gabbanaesteban authored Feb 3, 2021
1 parent e318f78 commit ab81414
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/Mastermind.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ protected function hasRightLength(array $code): bool
*/
protected function hasValidColors(array $code): bool
{
$filter = fn (string $color): bool => \in_array($color, self::VALID_COLORS, true);
$validColors = array_filter($code, $filter);

$validColors = array_intersect($code, self::VALID_COLORS);
return \count($validColors) === \count($code);
}
}

0 comments on commit ab81414

Please sign in to comment.