public static int Calculate(string[] sourceWords, string[] words) { List <int> wordDistances = new List <int>(); foreach (var w in words) { int minDistance = int.MaxValue; foreach (var sw in sourceWords) { var distance = Levenshtein.ComputeDistance(w.ToUpper(), sw.ToUpper()); minDistance = Math.Min(minDistance, distance); } wordDistances.Add(minDistance); } return((int)Math.Round(wordDistances.Average())); }
public static double Calculate(string[] sourceWords, string[] words) { if (!words.Any()) { return(0); } // Cannot evaluate List <double> wordDistances = new List <double>(); foreach (var w in words) { double minDistance = int.MaxValue; foreach (var sw in sourceWords) { var distance = Levenshtein.ComputeDistance(w.ToUpper(), sw.ToUpper()); minDistance = Math.Min(minDistance, distance); } wordDistances.Add(minDistance); } return(wordDistances.Average()); }