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 27 | 104x 89x 89x 56x 89x 9x 89x 9x 89x 68x 6x | import { Word, Lookup } from './types'
import { Node } from './node'
type SimplifiedNode = Word | Lookup | { [x: string]: Node[] } | null
type SimplifiedTrie = (SimplifiedTrie | SimplifiedNode)[]
export function simplify(node: Node, simplified: SimplifiedTrie = []): SimplifiedTrie {
let paths: SimplifiedTrie = []
for (const c of Object.values(node.next.char)) {
paths.push(simplify(c, [c.value]))
}
for (const w of Object.values(node.next.word)) {
paths.push(simplify(w, [' ', w.value as string]))
}
for (const r of Object.values(node.next.lookup)) {
paths.push(simplify(r, [{ [r.value as string]: r.contexts }]))
}
if (paths.length === 0) return simplified
if (paths.length === 1) return simplified.concat(paths[0])
return [...simplified, paths]
}
|