This repository has been archived on 2024-06-04. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
thesis-src/Examples/Common/Extensions/EnumerableExtensions.cs
T
Simon Gruber 4e35427e4c Checkpoint
2023-11-22 16:51:31 +01:00

17 lines
402 B
C#

namespace Common.Extensions;
public static class EnumerableExtensions
{
public static double Median(this IEnumerable<double> values)
{
var tValues = values.ToArray();
return tValues
.OrderBy(x => x)
.Skip(tValues.Length / 2)
.First();
}
public static double Median<T>(this IEnumerable<T> items, Func<T, double> selector) =>
items.Select(selector).Median();
}