Created
June 7, 2022 08:51
-
-
Save mrfrostikcz/5c2d4c751498586b65d6c62ff27bb206 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function battleResult(string $good, string $evil): string | |
{ | |
$good = $this->getFormattedResult($good); | |
$evil = $this->getFormattedResult($evil); | |
if ($good > $evil) { | |
return 'Battle Result: Good triumphs over Evil'; | |
} | |
if ($evil > $good) { | |
return 'Battle Result: Evil eradicates all trace of Good'; | |
} | |
return 'Battle Result: No victor on this battle field'; | |
} | |
private function getFormattedResult(string $score): int | |
{ | |
return array_sum(array_map(static fn(string $part) => (int) $part, explode(' ', $score))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment