lib/levenshtein.rb in levenshtein-0.1.0 vs lib/levenshtein.rb in levenshtein-0.1.1
- old
+ new
@@ -16,11 +16,11 @@
#
# More information about the Levenshtein distance algorithm:
# http://en.wikipedia.org/wiki/Levenshtein_distance .
module Levenshtein
- # Returns the Levenshtein distance as a number bestween 0.0 and 1.0.
+ # Returns the Levenshtein distance as a number between 0.0 and 1.0.
# It's basically the Levenshtein distance divided by the length of the longest string.
def self.normalized_distance(s1, s2, threshold=nil)
s1, s2 = s2, s1 if s1.length > s2.length # s1 is the short one; s2 is the long one.
@@ -60,10 +60,10 @@
while s1[b, 1] == s2[b, 1]
b += 1
end
- while s1[e1, 1] == s2[e2, 1]
+ while s1[e1, 1] == s2[e2, 1] and e1 > b and e2 > b
e1 -= 1
e2 -= 1
end
distance_part2(s1[b..e1], s2[b..e2], threshold)