Skip to content

Commit

Permalink
Secure index access and type safe comparision in statistic median
Browse files Browse the repository at this point in the history
  • Loading branch information
akondas committed Dec 6, 2016
1 parent 6d11116 commit 38a26d1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Phpml/Math/Statistic/Mean.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public static function median(array $numbers)
self::checkArrayLength($numbers);

$count = count($numbers);
$middleIndex = floor($count / 2);
$middleIndex = (int)floor($count / 2);
sort($numbers, SORT_NUMERIC);
$median = $numbers[$middleIndex];

if (0 == $count % 2) {
if (0 === $count % 2) {
$median = ($median + $numbers[$middleIndex - 1]) / 2;
}

Expand Down

0 comments on commit 38a26d1

Please sign in to comment.