| | import {TranslationSentences} from './types/StreamingTypes'; |
| |
|
| | export function getTotalSentencesLength( |
| | translatedSentences: TranslationSentences, |
| | ) { |
| | return translatedSentences.reduce((acc, curr) => acc + curr.length, 0); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | export function sliceTranslationSentencesUpToIndex( |
| | translatedSentences: TranslationSentences, |
| | targetIndex: number, |
| | ): TranslationSentences { |
| | return translatedSentences.reduce<TranslationSentences>((acc, sentence) => { |
| | const accTotalLength = getTotalSentencesLength(acc); |
| | if (accTotalLength === targetIndex) { |
| | return acc; |
| | } |
| | |
| | if (accTotalLength + sentence.length <= targetIndex) { |
| | return [...acc, sentence]; |
| | } |
| | |
| | return [...acc, sentence.slice(0, targetIndex - accTotalLength)]; |
| | }, []); |
| | } |
| |
|