Skip to content

Instantly share code, notes, and snippets.

@kubikowski
kubikowski / levenshtein-distance.ts
Created January 26, 2024 20:16
[TypeScript] Levenshtein Distance
/**
* This is a simple and performant implementation of
* the Wagner–Fischer algorithm for computing
* the Levenshtein Distance between two strings.
*
* It is based on the observation that we can reserve a matrix
* to hold the Levenshtein distances between all prefixes of
* the first string and all prefixes of the second.
*
* Then we can compute the values in the matrix