Skip to content

Commit

Permalink
refactor(text): prepare for noUncheckedIndexedAccess (denoland#4148)
Browse files Browse the repository at this point in the history
  • Loading branch information
syhol committed Jan 10, 2024
1 parent 2292c2b commit a4d02ab
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion text/_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export function splitToWords(input: string) {

export function capitalizeWord(word: string): string {
return word
? word[0].toLocaleUpperCase() + word.slice(1).toLocaleLowerCase()
? word?.[0]?.toLocaleUpperCase() + word.slice(1).toLocaleLowerCase()
: word;
}
2 changes: 1 addition & 1 deletion text/closest_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function closestString(
givenWord = givenWord.toLowerCase();
}

let nearestWord = possibleWords[0];
let nearestWord = possibleWords[0]!;
let closestStringDistance = Infinity;
for (const each of possibleWords) {
const distance = caseSensitive
Expand Down
10 changes: 5 additions & 5 deletions text/levenshtein_distance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ export function levenshteinDistance(str1: string, str2: string): number {
const char1 = str1[str1Index];
const char2 = str2[str2Index];
if (char1 === char2) {
tempDistances.push(distances[str1Index]);
tempDistances.push(distances[str1Index]!);
} else {
tempDistances.push(
1 +
Math.min(
distances[str1Index],
distances[str1Index + 1],
tempDistances[tempDistances.length - 1],
distances[str1Index]!,
distances[str1Index + 1]!,
tempDistances.at(-1)!,
),
);
}
}
distances = tempDistances;
}
return distances[distances.length - 1];
return distances.at(-1)!;
}

0 comments on commit a4d02ab

Please sign in to comment.