Skip to content
This repository has been archived by the owner on May 1, 2023. It is now read-only.

Doesn't work for strings with length 1 #33

Open
taylorjacklespriggs opened this issue Feb 28, 2019 · 1 comment
Open

Doesn't work for strings with length 1 #33

taylorjacklespriggs opened this issue Feb 28, 2019 · 1 comment

Comments

@taylorjacklespriggs
Copy link

taylorjacklespriggs commented Feb 28, 2019

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.

if (first.length < 2 || second.length < 2) return 0; // if either is a 1-letter string

@jechazelle
Copy link

Hello @taylorjacklespriggs, did you found a solution ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants