hiddentao / fast-levenshtein

Efficient Javascript implementation of Levenshtein algorithm with locale-specific collator support.
MIT License
597 stars 56 forks source link

returning the wrong distance #23

Open zdrd opened 7 years ago

zdrd commented 7 years ago

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
hiddentao commented 7 years ago

I guess it's the character code (\n) which trips it up?

gustf commented 7 years ago

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 :)