#include "stats.h" #include #include double med(std::vector &scores,bool ignoreExtremes) { const auto len = scores.size() - (ignoreExtremes && scores.size() > 2) ? 2 : 0; sort(scores.begin(), scores.end()); using vec_size = std::vector::size_type; const vec_size middle = (vec_size) (len / 2); if (middle%2 == 1) return scores[middle]; else return (scores[middle - 1] + scores[middle]) / 2.0; } double avg(const std::vector &scores,bool ignoreExtremes) { auto sum = 0.0; using vec_size = std::vector::size_type; for (vec_size i = (ignoreExtremes && scores.size() > 2) ? 1 : 0; i < scores.size() - (ignoreExtremes && scores.size() > 2) ? 1 : 0; i++) sum += scores[i]; return sum / static_cast(scores.size() - (ignoreExtremes && scores.size() > 2) ? 2 : 0); }