From ceca35cccba0c5ce002187ca2cbc329f228818c5 Mon Sep 17 00:00:00 2001 From: Eddie Antonio Santos Date: Thu, 30 Apr 2020 19:20:47 -0600 Subject: [PATCH] refactor(common/lmlayer): extract function: appendToTopOfStack() --- .../word_breaking/join-word-breaker-decorator.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/common/predictive-text/worker/word_breaking/join-word-breaker-decorator.ts b/common/predictive-text/worker/word_breaking/join-word-breaker-decorator.ts index 4cda1e0480..dcb1ced5cf 100644 --- a/common/predictive-text/worker/word_breaking/join-word-breaker-decorator.ts +++ b/common/predictive-text/worker/word_breaking/join-word-breaker-decorator.ts @@ -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!