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 0d1bac9787..d912d62362 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 @@ -63,9 +63,11 @@ namespace wordBreakers { } function concatLastSpanInStackWith(span: Span) { - let top = stack.pop(); + let lastIndex = stack.length - 1; + + let top = stack[lastIndex]; let joinedSpan = concatenateSpans(top, span); - stack.push(joinedSpan); + stack[lastIndex] = joinedSpan; } }