refactor(common/lmlayer): extract function: appendToTopOfStack()

This commit is contained in:
Eddie Antonio Santos 2020-04-30 19:20:47 -06:00
parent 301870f7d7
commit ceca35cccb
No known key found for this signature in database
GPG key ID: DD411EA4D9509D87

View file

@ -41,9 +41,7 @@ namespace wordBreakers {
if (includes(delimiters, span.text)) {
// well, now we should join them!
if (spansAreBackToBack(lastFrom(stack), span)) {
let top = stack.pop();
let joinedSpan = concatenateSpans(top, span);
stack.push(joinedSpan);
appendToTopOfStack(span);
} else {
stack.push(span);
}
@ -62,9 +60,7 @@ namespace wordBreakers {
break;
}
let top = stack.pop();
let joinedSpan = concatenateSpans(top, span);
stack.push(joinedSpan);
appendToTopOfStack(span);
if (includes(delimiters, span.text)) {
state = State.JOINED;
@ -76,8 +72,15 @@ namespace wordBreakers {
}
return stack;
function appendToTopOfStack(span: Span) {
let top = stack.pop();
let joinedSpan = concatenateSpans(top, span);
stack.push(joinedSpan);
}
}
/**
* Returns true when the spans are contiguous.
* Order matters when calling this function!