Skip to content

Instantly share code, notes, and snippets.

View felixeichler's full-sized avatar

Felix Eichler felixeichler

View GitHub Profile
@felixeichler
felixeichler / levenshtein.ts
Last active July 11, 2024 13:00 — forked from andrei-m/levenshtein.js
Levenshtein distance between two given strings implemented in JavaScript and usable as a Node.js module
/**
* Computes the Levenshtein distance between two strings (a number that tells you how different two strings are).
* The higher the number, the more different the two strings are.
* Original source: https://gist.github.com/andrei-m/982927/0efdf215b00e5d34c90fdc354639f87ddc3bd0a5
*/
const getLevenshteinDistance = (a: string, b: string): number => {
if (a.length == 0) return b.length;
if (b.length == 0) return a.length;
const matrix = [];