using System.Collections.Generic;
using System.Linq;
namespace UglyToad.PdfPig.DocumentLayoutAnalysis
{
///
/// Useful math extensions.
///
public static class MathExtensions
{
///
/// Computes the mode of a sequence of float values.
///
/// The array of floats.
public static float Mode(this IEnumerable array)
{
if (array == null || array.Count() == 0) return float.NaN;
return array.GroupBy(v => v).OrderByDescending(g => g.Count()).First().Key;
}
///
/// Computes the mode of a sequence of decimal values.
///
/// The array of decimal.
public static decimal Mode(this IEnumerable array)
{
return array.GroupBy(v => v).OrderByDescending(g => g.Count()).First().Key;
}
}
}