From ddbc3d2f4a01d63e7fa86181131b047d55b9d024 Mon Sep 17 00:00:00 2001 From: Eddie Antonio Santos Date: Fri, 24 Apr 2020 14:59:48 -0600 Subject: [PATCH] change(common/lmlayer): use limit instead of useless array as parameter --- .../word_breaking/join-word-breaker-decorator.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 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 266f39481e..6566072fb1 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 @@ -42,7 +42,7 @@ namespace wordBreakers { } }); - // Some indices push above are out of range. + // Some indices pushed above are out of range. // Get rid of them! if (messyJoinRanges.length > 0) { if (messyJoinRanges[0][0] < 0) { @@ -57,18 +57,22 @@ namespace wordBreakers { return mergeOverlappingRanges(messyJoinRanges); } - function fillInGapsInRanges(joinRanges: number[][], originalResults: T[]) { + /** + * Given an array of ranges of indices that may have "gaps", + * e.g., not covering all indices less than {limit}, + * fills in those gaps with "singleton" ranges. + */ + function fillInGapsInRanges(joinRanges: number[][], limit: number) { let contiguousRanges: number[][] = []; let insideRange = false; let currentJoin = joinRanges.shift(); - originalResults.forEach((_, index) => { + for (let index = 0; index < limit; index++) { if (insideRange) { if (index === lastFrom(currentJoin)) { insideRange = false; currentJoin = joinRanges.shift(); } - } - else { + } else { if (currentJoin && index === currentJoin[0]) { insideRange = true; contiguousRanges.push(currentJoin);