string-similarity
string-similarity copied to clipboard
Doesn't work for strings with length 1
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
Hello @taylorjacklespriggs, did you found a solution ?