Skip to content

Commit

Permalink
Remove Integer floor and prefix index from Jaro distance
Browse files Browse the repository at this point in the history
The variable ``length2`` is an Integer, call to floor returns self.
The variables ``i`` and ``prefix_bonus`` are equally incremented, no need to keep the ``i`` variable.
  • Loading branch information
Maumagnaguagno authored Jan 25, 2023
1 parent 0f4b080 commit 4408802
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/did_you_mean/jaro_winkler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def distance(str1, str2)

m = 0.0
t = 0.0
range = (length2 / 2).floor - 1
range = length2 / 2 - 1
range = 0 if range < 0
flags1 = 0
flags2 = 0
Expand Down Expand Up @@ -72,10 +72,8 @@ def distance(str1, str2)
codepoints2 = str2.codepoints
prefix_bonus = 0

i = 0
str1.each_codepoint do |char1|
char1 == codepoints2[i] && i < 4 ? prefix_bonus += 1 : break
i += 1
char1 == codepoints2[prefix_bonus] && prefix_bonus < 4 ? prefix_bonus += 1 : break
end

jaro_distance + (prefix_bonus * WEIGHT * (1 - jaro_distance))
Expand Down

0 comments on commit 4408802

Please sign in to comment.