using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Common.Helper
{
public class JsHelper
{
///
/// 计算使用最多的数字
///
/// 字符串集合
/// 需要几位
///
public static IEnumerable UseMax(List list, int number = 3)
{
list = list.Where(p => !string.IsNullOrEmpty(p)).ToList();
var dict = new Dictionary();
var group = list.GroupBy(p => p).ToList();
group.ForEach(p =>
{
dict.Add(p.Key, list.Where(q => q == p.Key).Count());
});
var dictOrder = dict.OrderByDescending(p => p.Value);
if (list.Count > 0)
{
number = dictOrder.Count() > number ? number : dictOrder.Count();
var i = 1;
foreach (var item in dictOrder)
{
if (i <= number)
yield return item.Key;
i++;
}
}
}
///
/// 计算使用最多的数字
///
/// 字符串集合
/// 需要几位
///
public static string UseMaxString(List list, int number = 3)
{
return UseMax(list, number).Join();
}
}
}