Levenshtein Algorithm
For the levenshtein algorithm definition and algorithm principles, see this article.Article: A fast and efficient levenshtein Algorithm Implementation
Javascript implementation
Function Levenshteindistance (S, T ){ If (S. length> T. Length ){ VaR Temp = S; s = T; t = Temp; Delete Temp ;} VaR N =S. length; VaR M = T. length; If (M = 0 ){ Return N ;} Else If (N = 0 ){ Return M ;} VaR V0 = []; For (VaR I = 0; I <= m; I ++ ) {V0 [I] = I ;} VaR V1 = New Array (n + 1 ); VaR Cost = 0 ; For ( VaR I = 1; I <= N; I ++ ){ If (I> 1 ) {V0 = V1.slice (0);} V1 [ 0] = I; For ( VaR J = 1; j <= m; j ++ ){ If (S [I-1]. tolowercase () = T [J-1 ]. Tolowercase () {cost = 0 ;} Else {Cost = 1 ;} V1 [J] = Math. Min. Call ( Null , V1 [J-1] + 1, V0 [J] + 1, V0 [J-1] +Cost );}} Return V1.pop ();} // Test Levenshteindistance ("Gumbo", "gambol "); // Output 2