From 927768e6b22d5ffe8043625362247232a5fc3365 Mon Sep 17 00:00:00 2001 From: Frank Seifferth Date: Fri, 11 Oct 2019 17:39:15 +0100 Subject: [PATCH] Replace charAt with index notation in levenshtein.coffee 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. --- src/levenshtein.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/levenshtein.coffee b/src/levenshtein.coffee index 3551f95..6b57da9 100644 --- a/src/levenshtein.coffee +++ b/src/levenshtein.coffee @@ -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),