summaryrefslogtreecommitdiff
path: root/AK/Statistics.h
diff options
context:
space:
mode:
authorMusab Kılıç <musabkilic@protonmail.com>2021-10-29 15:59:52 +0300
committerBrian Gianforcaro <b.gianfo@gmail.com>2021-11-06 22:09:25 -0700
commitf6a43c7cf5fda9bcb61b5feb72566736331625d3 (patch)
tree5b7e214635dde125679af0f02da470cd06697a25 /AK/Statistics.h
parent5c75216361d79b1cf1c842c4ac023d71470b72d0 (diff)
downloadserenity-f6a43c7cf5fda9bcb61b5feb72566736331625d3.zip
AK: Add min and max functions to Statistics
Diffstat (limited to 'AK/Statistics.h')
-rw-r--r--AK/Statistics.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/AK/Statistics.h b/AK/Statistics.h
index f8063caa87..a74400fb05 100644
--- a/AK/Statistics.h
+++ b/AK/Statistics.h
@@ -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()
{