UNPKG

braid-design-system

Version:
19 lines (18 loc) 466 B
function reverseMatches(suggestion, matches) { const suggestionLength = suggestion.length; const reversedMatches = []; let currentStart = 0; for (const [start, end] of matches) { if (currentStart < start) { reversedMatches.push([currentStart, start]); } currentStart = end; } if (currentStart < suggestionLength) { reversedMatches.push([currentStart, suggestionLength]); } return reversedMatches; } export { reverseMatches };