Last active
February 27, 2018 10:07
-
-
Save RobDWaller/2e01bf76ad4bc21ef7b4cc00fc378457 to your computer and use it in GitHub Desktop.
Dave's Code
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 | |
function everyValueDivisibleByFive($array) | |
{ | |
$newArray = []; | |
if (!count($array)) { | |
$result = 'error'; | |
} | |
else { | |
foreach ($array as $row) { | |
if ($row % 5 != 0) { | |
$remainder = $row % 5; | |
if (5 - $remainder < 3) { | |
$addition = 5 - $remainder; | |
$newArray[] = $row + $addition; | |
} | |
else { | |
$newArray[] = $row - $remainder; | |
} | |
} | |
else { | |
$newArray[] = $row; | |
} | |
} | |
$result = $newArray; | |
} | |
return $result; | |
} | |
$result = everyValueDivisibleByFive([1, 7, 12, 18, 23, 34, 45]); | |
var_dump($result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment