refactor(common/lmlayer): extract function: spansAreBackToBack

This commit is contained in:
Eddie Antonio Santos 2020-04-28 15:55:01 -06:00
parent 73591cb977
commit acf7aab588
No known key found for this signature in database
GPG key ID: DD411EA4D9509D87

View file

@ -46,12 +46,13 @@ namespace wordBreakers {
let current: Span | undefined = results[index];
let window = [];
if (previous && previous.end === current.start) {
if (previous && spansAreBackToBack(previous, current)) {
window.push(index - 1);
}
window.push(index);
if (next && current.end === next.start) {
if (next && spansAreBackToBack(current, next)) {
window.push(index + 1);
}
@ -92,6 +93,14 @@ namespace wordBreakers {
return contiguousRanges;
}
/**
* Returns true when the spans are contiguous.
* Order matters when calling this function!
*/
function spansAreBackToBack(former: Span, latter: Span): boolean {
return former.end === latter.start;
}
/**
* Given an array of ranges of indices, and the corresponding spans,
* concatenates spans according to the ranges of indices.