-
-
Notifications
You must be signed in to change notification settings - Fork 587
Expand file tree
/
Copy pathAbsoluteMax.php
More file actions
30 lines (26 loc) · 692 Bytes
/
Copy pathAbsoluteMax.php
File metadata and controls
30 lines (26 loc) · 692 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
declare(strict_types=1);
/**
* This function calculates
* Absolute max values from
* the different numbers
* provided
*
* @param decimal $numbers A variable sized number input
* @return decimal $absoluteMax Absolute max value
* @throws \Exception
*/
function absolute_max(...$numbers)
{
if ($numbers === []) {
throw new \Exception('Please pass values to find absolute max value');
}
$absoluteMax = $numbers[0];
$counter = count($numbers);
for ($loopIndex = 0; $loopIndex < $counter; $loopIndex++) {
if ($numbers[$loopIndex] > $absoluteMax) {
$absoluteMax = $numbers[$loopIndex];
}
}
return $absoluteMax;
}