levenshteinDistance
import { levenshteinDistance } from "jsr:@ende/text";function
function levenshteinDistance(str1: string, str2: string): numberCalculates the Levenshtein distance between two strings.
Note
The complexity of this function is O(m * n), where m and n are the lengths of the two strings. It's recommended to limit the length and validate input if arbitrarily accepting input.
str1: stringThe first string.
str2: stringThe second string.
Returns
The Levenshtein distance between the two strings.
Example: Usage
import { levenshteinDistance } from "@ende/text/levenshtein-distance";
import { assertEquals } from "@ende/assert";
assertEquals(levenshteinDistance("aa", "bb"), 2);