mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-08-16 17:00:35 +03:00
AK: Add min and max functions to Statistics
This commit is contained in:
parent
5c75216361
commit
f6a43c7cf5
Notes:
sideshowbarker
2024-07-18 01:27:04 +09:00
Author: https://github.com/musabkilic Commit: https://github.com/SerenityOS/serenity/commit/f6a43c7cf5f Pull-request: https://github.com/SerenityOS/serenity/pull/10680 Reviewed-by: https://github.com/alimpfard
@ -29,6 +29,28 @@ public:
|
||||
T const sum() const { return m_sum; }
|
||||
float average() const { return (float)sum() / size(); }
|
||||
|
||||
T const min() const
|
||||
{
|
||||
T minimum = m_values[0];
|
||||
for (T number : values()) {
|
||||
if (number < minimum) {
|
||||
minimum = number;
|
||||
}
|
||||
}
|
||||
return minimum;
|
||||
}
|
||||
|
||||
T const max() const
|
||||
{
|
||||
T maximum = m_values[0];
|
||||
for (T number : values()) {
|
||||
if (number > maximum) {
|
||||
maximum = number;
|
||||
}
|
||||
}
|
||||
return maximum;
|
||||
}
|
||||
|
||||
// FIXME: Implement a better algorithm
|
||||
T const median()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user