( target: string, xs: string[] )
| 164 | } |
| 165 | |
| 166 | export function closestMatch( |
| 167 | target: string, |
| 168 | xs: string[] |
| 169 | ): { closest: string; score: number } { |
| 170 | const [firstCandidate, ...rest] = xs; |
| 171 | |
| 172 | if (!firstCandidate) { |
| 173 | return { closest: target, score: 0 }; |
| 174 | } |
| 175 | |
| 176 | const normalizedTarget = normalizeForComparison(target); |
| 177 | |
| 178 | let closest = firstCandidate; |
| 179 | let closestScore = getSimilarityScore( |
| 180 | normalizedTarget, |
| 181 | normalizeForComparison(closest) |
| 182 | ); |
| 183 | |
| 184 | for (const candidate of rest) { |
| 185 | const score = getSimilarityScore( |
| 186 | normalizedTarget, |
| 187 | normalizeForComparison(candidate) |
| 188 | ); |
| 189 | |
| 190 | if (score > closestScore) { |
| 191 | closest = candidate; |
| 192 | closestScore = score; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | return { closest, score: closestScore }; |
| 197 | } |
| 198 | |
| 199 | export function closestFilters( |
| 200 | superblocks: Filterable[], |
no test coverage detected