// ---------------------------------------------------------------------- public static string[] FilterAndSort(string search, string[] lst, float minScore) { var scores = GetScores(search, lst); var ts = P.zip(scores, lst); var filtered = P.filter((t) => t.Item1 > minScore, ts); P.sort( filtered, (t1, t2) => { var diff = t2.Item1 - t1.Item1; return(Math3D.IsZero(diff) ? 0 : (diff < 0 ? -1 : 1)); } ); return(P.map((t) => P.uncurry((score, str) => str, t), filtered)); }
// ---------------------------------------------------------------------- public static string[] SortAndTake(string search, string[] lst, int maxNbOfResults) { var scores = GetScores(search, lst); var toSort = P.zip(scores, lst); P.sort( toSort, (t1, t2) => { var diff = t2.Item1 - t1.Item1; return(Math3D.IsZero(diff) ? 0 : (diff < 0 ? -1 : 1)); } ); var result = P.take(maxNbOfResults, toSort); return(P.map((t) => P.uncurry((score, str) => str, t), result)); }