Passed
Branch master (a9ed3d)
by Daniel
23:14 queued 31s
created

althighAndLow()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
In this little assignment you are given a string of space separated numbers, and have to return the highest and lowest number.
4
5
Example:
6
7
highAndLow("1 2 3 4 5");  // return "5 1"
8
highAndLow("1 2 -3 4 5"); // return "5 -3"
9
highAndLow("1 9 3 4 -5"); // return "9 -5"
10
11
Notes:
12
13
    All numbers are valid Int32, no need to validate them.
14
    There will always be at least one number in the input string.
15
    Output string must be two numbers separated by a single space, and highest number is first.
16
*/
17
18
function highAndLow($numbers)
19
{
20
    $splitNumbers = explode(" ", $numbers);
21
    $highestNumber = max($splitNumbers);
22
    $lowestNumber = min($splitNumbers);
23
    return "$highestNumber $lowestNumber";
24
}
25
26
// Alternate solution
27
28
function althighAndLow($numbers)
29
{
30
    $splitNumbers = explode(" ", $numbers);
31
    return max($splitNumbers) . " " . min($splitNumbers);
32
}
33