mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-07 10:06:03 +00: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: f6a43c7cf5
Pull-request: https://github.com/SerenityOS/serenity/pull/10680
Reviewed-by: https://github.com/alimpfard
1 changed files with 22 additions and 0 deletions
|
@ -29,6 +29,28 @@ public:
|
||||||
T const sum() const { return m_sum; }
|
T const sum() const { return m_sum; }
|
||||||
float average() const { return (float)sum() / size(); }
|
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
|
// FIXME: Implement a better algorithm
|
||||||
T const median()
|
T const median()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue