tales 6a67bf2606
mean, median, mode (#83)
* mean median mode

* update DIRECTORY

* just renaming

* adding unit tests

* organizing the file

* ops missed this one
2022-10-15 22:41:56 -06:00

20 lines
442 B
PHP

<?php
/**
* This function calculates
* The mode value of
* numbers provided
*
* @param decimal $numbers A variable sized number input
* @return decimal $mode Mode of provided numbers
*/
function mode(...$numbers)
{
if (empty($numbers)) {
throw new \Exception('Please pass values to find mean value');
}
$values = array_count_values($numbers);
$mode = array_search(max($values), $values);
return $mode;
}