fast-levenshtein
fast-levenshtein copied to clipboard
returning the wrong distance
I came across an instance of this returning the incorrect distance, here is a full code snippet to reproduce:
var levenshtein = require('fast-levenshtein');
var a = 'A Microbial communities are very vital in the function of all ecosystems';
var b1 = 'Microbial communities are vital in the functioning of all ecosystems;';
var b2 = 't\nMicrobial communities are vital in the functioning of all ecosystems;';
var leven1 = levenshtein.get(a, b1);
console.log(leven1); // returns 11 correctly
var leven2 = levenshtein.get(a, b2);
console.log(leven2); // should return 12, but returns 11 which is incorrect
I guess it's the character code (\n
) which trips it up?
It is actually correct with 11, \n
is only one character, i.e the newline character.
I guess thats what you also say @hiddentao, but just to clarify :)