Created
November 15, 2018 02:36
-
-
Save iCaspar/7becd5b72568b6dc0fb390282b8bb2fe to your computer and use it in GitHub Desktop.
Has 5s recursive method to find numbers with 5s in them.
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
/** | |
* Does this number have 5s? | |
* | |
* @param $number Number to check. | |
* | |
* @since 1.0.0 | |
* | |
* @return bool | |
*/ | |
private function hasFive($number): bool | |
{ | |
$number = abs($number); | |
while ($number) { | |
if ($number % 10 == 5) { | |
return true; | |
} | |
$number = floor($number / 10); | |
return $this->hasFive($number); | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment