Created
February 15, 2014 09:22
-
-
Save StoneCypher/9016629 to your computer and use it in GitHub Desktop.
Javascript Levenshtein
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function levenshtein (s, t) { | |
if (!s.length) { return t.length; } | |
if (!t.length) { return s.length; } | |
return Math.min( | |
levenshtein(s.substr(1), t) + 1, | |
levenshtein(t.substr(1), s) + 1, | |
levenshtein(s.substr(1), t.substr(1)) + (s[0] !== t[0] ? 1 : 0) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment