Function levenshteinDistance

  • Calculates 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.

    Parameters

    • str1: string

      The first string.

    • str2: string

      The second string.

    Returns number

    The Levenshtein distance between the two strings.

    import { levenshteinDistance } from "@std/text/levenshtein-distance";
    import { assertEquals } from "@std/assert";

    assertEquals(levenshteinDistance("aa", "bb"), 2);