Skip to content

Commit

Permalink
Replace charAt with index notation in levenshtein.coffee
Browse files Browse the repository at this point in the history
Using charAt restricts the library's usage to comparing strings
only. Using plain index notation allows to use it on arbitrary
lists as well: e. g. for calculating the levenshtein distance
in words between tokenized texts.
  • Loading branch information
seifferth committed Oct 11, 2019
1 parent 2e8f64b commit 927768e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/levenshtein.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ levenshtein = (stringA, stringB, insertCb, removeCb, updateCb) ->

for i in [1..a.length] by 1
for j in [1..b.length] by 1
aC = a.charAt(i - 1)
bC = b.charAt(j - 1)
aC = a[i - 1]
bC = b[j - 1]
min = trackedMin(
dist[i - 1][j] + removeCb(aC),
dist[i][j - 1] + insertCb(bC),
Expand Down

0 comments on commit 927768e

Please sign in to comment.