TheAlgorithms / PHP

All Algorithms implemented in PHP
MIT License
2.15k stars 468 forks source link

Enhance mode() Function to Return Multiple Modes #117

Closed salehhashemi1992 closed 1 year ago

salehhashemi1992 commented 1 year ago

Enhance the mode() function to return an array of all mode values instead of returning just a single mode value.

According to mathematical definitions, a dataset can have multiple modes (bimodal or multimodal distributions). This update aligns the mode() function with this mathematical truth, making it more accurate and useful.

Added unit tests to confirm that: An array of a single mode is returned when there is one mode. An array of multiple modes is returned when there are multiple modes. An array of all numbers is returned when each number is unique and thus all are modes.