string-similarity icon indicating copy to clipboard operation
string-similarity copied to clipboard

Doesn't work for strings with length 1

Open taylorjacklespriggs opened this issue 6 years ago • 1 comments

This looks like expected behavior, but it could be useful to fall back to a simple algorithm if one of the inputs is a length 1 string.

  if (first.length === 1 || second.length === 1) {			           // if either is a 1-letter string
    let [smaller, larger] = (first.length === 1)
      ? [first, second]
      : [second, first];
    return larger.includes(smaller) ? 2.0 / (larger.length + 1) : 0;
  }

This came up when I tried to use compareTwoStrings for a search ranking. https://github.com/aceakash/string-similarity/blob/ccdb537a886d640c1d1fd437414d037ec615562e/compare-strings.js#L14

taylorjacklespriggs avatar Feb 28 '19 01:02 taylorjacklespriggs

Hello @taylorjacklespriggs, did you found a solution ?

jechazelle avatar Jan 13 '20 19:01 jechazelle