574
}
575
576
>
function normalizeMatches(matches: IMatch[]): IMatch[] {
fuzzyScorer.ts
577
>
578
>
// sort matches by start to be able to normalize
579
>
const sortedMatches = matches.sort((matchA, matchB) => {
580
>
return matchA.start - matchB.start;
581
>
});
582
>
583
>
// merge matches that overlap
584
>
const normalizedMatches: IMatch[] = [];
585
>
let currentMatch: IMatch | undefined = undefined;
586
>
for (const match of sortedMatches) {
587
>
588
>
// if we have no current match or the matches
589
>
// do not overlap, we take it as is and remember
590
>
// it for future merging
591
>
if (!currentMatch || !matchOverlaps(currentMatch, match)) {
592
>
currentMatch = match;
593
>
normalizedMatches.push(match);
594
>
}
595
596
// otherwise we merge the matches