A world-class math input for the web
at main 26 lines 790 B view raw
1export type StrandPath = { tokenIndex: number; childIndex: number }[]; 2export type TokenPath = { 3 strandPath: StrandPath; 4 tokenIndex: number; 5}; 6 7export function strandPathsEqual(a: StrandPath, b: StrandPath): boolean { 8 if (a.length !== b.length) return false; 9 for (let i = 0; i < a.length; i++) { 10 if (a[i].tokenIndex !== b[i].tokenIndex) return false; 11 if (a[i].childIndex !== b[i].childIndex) return false; 12 } 13 return true; 14} 15 16export function strandPathIsAncestor( 17 parent: StrandPath, 18 child: StrandPath 19): boolean { 20 if (parent.length >= child.length) return false; 21 for (let i = 0; i < parent.length; i++) { 22 if (parent[i].tokenIndex !== child[i].tokenIndex) return false; 23 if (parent[i].childIndex !== child[i].childIndex) return false; 24 } 25 return true; 26}