mirror of
https://github.com/TheAlgorithms/PHP.git
synced 2025-01-17 23:28:14 +01:00
6a67bf2606
* mean median mode * update DIRECTORY * just renaming * adding unit tests * organizing the file * ops missed this one
20 lines
442 B
PHP
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;
|
|
} |