Toolbox-XToolbox-X

Get Levenshtein Distance

Computes the Levenshtein distance between two strings.

getLevenshteinDistance

The getLevenshteinDistance function computes the Levenshtein distance between two strings, measuring the difference between them based on the minimum number of single-character insertions, deletions, or substitutions required to transform one string into the other.

Function Signature

function getLevenshteinDistance(str1: string, str2: string): number

Parameters

  • str1 (string): First string to compare.
  • str2 (string): Second string to compare.

Return Value

  • number: The Levenshtein distance.

Example Usage

playground.ts

Notes

  • The comparison is case-sensitive (e.g. "kitten" and "Kitten" have a distance of 1).
  • The implementation is space-optimized, using O(min(len(str1), len(str2))) space.

Aliases

The following aliases can be used for the getLevenshteinDistance function:

  • levenshteinDistance

See Also

  • String Diff - For a visual diff tool comparing two strings.

Last updated: Sun, Jun 14, 2026 07:56:43AM (UTC)

On this page