Refactoring: fix small errors, simplify 'sortedByLevehnstein'-function, improve error messgae

This commit is contained in:
Pieter Vander Vennet 2025-07-03 17:33:29 +02:00
parent 97b8202b14
commit 8a0023377a
13 changed files with 27 additions and 19 deletions

View file

@ -1259,11 +1259,21 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
}
}
public static sortedByLevenshteinDistance(
reference: string,
ts: ReadonlyArray<string>
): string[]
public static sortedByLevenshteinDistance<T>(
reference: string,
ts: ReadonlyArray<T>,
getName: (t: T) => string
): string[]
public static sortedByLevenshteinDistance<T>(
reference: string,
ts: ReadonlyArray<T>,
getName?: (t: T) => string
): T[] {
getName ??= (str) => <string> str;
const withDistance: [T, number][] = ts.map((t) => [
t,
Utils.levenshteinDistance(getName(t), reference),