936
return top;
937
}
939
>
if (pattern.length >= 3) {
940
>
// When the pattern is long enough then try a few (max 7)
941
>
// permutations of the pattern to find a better match. The
942
>
// permutations only swap neighbouring characters, e.g
943
>
// `cnoso` becomes `conso`, `cnsoo`, `cnoos`.
944
>
const tries = Math.min(7, pattern.length - 1);
945
>
for (let movingPatternPos = patternPos + 1; movingPatternPos < tries; movingPatternPos++) {
946
>
const newPattern = nextTypoPermutation(pattern, movingPatternPos);
947
>
if (newPattern) {
948
>
const candidate = fuzzyScore(newPattern, newPattern.toLowerCase(), patternPos, word, lowWord, wordPos, options);
949
>
if (candidate) {
950
candidate[0] -= 3; // permutation penalty
951
if (!top || candidate[0] > top[0]) {