|
SortedCollection median does not work correctly for even amount of elements. Median, by definition (see links below for possible definitions and explanations of median), returns middle element of sorted numbers in case of odd-sized collections. In even-sized collections, there is no precisely middle element (in 4-sized collection the 2nd and 3rd are kinda both in the middle), therefore median is defined as average of these two "middle" elements (in case of 4-sized collection, it is average of 2nd and 3rd element). However, current implementation of SortedCollection>>#median just returns element before the "middle", so (in case of 4-sized collection), it returns 2nd element, although it should return average of 2nd and 3rd.
I understand that median can be sent even to collections of strings, classes or whatever that cannot be averaged, but this way it does not comply to definition of median and therefore should not be called that.
https://www.dictionary.com/browse/median https://searchdatacenter.techtarget.com/definition/statistical-mean-median-mode-and-range https://en.wikipedia.org/wiki/Median
Jan
|
|
|
Priority: 5 – Fix If Time
|
|
Status: Work Needed
|
|
Assigned to: Everyone
|
|
Milestone: Later
|
Go to Case
|
|