mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2025-01-11 17:38:50 +00:00
Secure index access and type safe comparision in statistic median
This commit is contained in:
parent
6d11116994
commit
38a26d185f
@ -34,11 +34,11 @@ class Mean
|
|||||||
self::checkArrayLength($numbers);
|
self::checkArrayLength($numbers);
|
||||||
|
|
||||||
$count = count($numbers);
|
$count = count($numbers);
|
||||||
$middleIndex = floor($count / 2);
|
$middleIndex = (int)floor($count / 2);
|
||||||
sort($numbers, SORT_NUMERIC);
|
sort($numbers, SORT_NUMERIC);
|
||||||
$median = $numbers[$middleIndex];
|
$median = $numbers[$middleIndex];
|
||||||
|
|
||||||
if (0 == $count % 2) {
|
if (0 === $count % 2) {
|
||||||
$median = ($median + $numbers[$middleIndex - 1]) / 2;
|
$median = ($median + $numbers[$middleIndex - 1]) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user