Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x | import { numberToClipIds } from './numberToClipIds'
/**
* Convert a problem's terms into an array of clip IDs.
*
* Parallel to `termsToSentence` but returns clip ID strings
* instead of an English sentence.
*
* Examples:
* termsToClipIds([5, 3]) → ['number-5', 'operator-plus', 'number-3']
* termsToClipIds([10, -3]) → ['number-10', 'operator-minus', 'number-3']
* termsToClipIds([5, 3, -2]) → ['number-5', 'operator-plus', 'number-3', 'operator-minus', 'number-2']
*/
export function termsToClipIds(terms: number[]): string[] {
if (terms.length === 0) return []
const clips: string[] = [...numberToClipIds(Math.abs(terms[0]))]
for (let t = 1; t < terms.length; t++) {
clips.push(terms[t] < 0 ? 'operator-minus' : 'operator-plus')
clips.push(...numberToClipIds(Math.abs(terms[t])))
}
return clips
}
|