diff options
| author | Terry Truong <terry06890@gmail.com> | 2022-03-29 11:39:33 +1100 |
|---|---|---|
| committer | Terry Truong <terry06890@gmail.com> | 2022-03-29 13:30:50 +1100 |
| commit | a68a55205ed189250693368af7028031a70631d9 (patch) | |
| tree | 4d780d1b450a2a3a51866103e80c53a818a8cb23 /src/tol.ts | |
| parent | 304274b1380f955b6e1913428f6dbbc9efcf0bcf (diff) | |
Update comments, adjust names, do minor refactors
Diffstat (limited to 'src/tol.ts')
| -rw-r--r-- | src/tol.ts | 9 |
1 files changed, 4 insertions, 5 deletions
@@ -1,5 +1,5 @@ /* - * Contains classes used for representing tree-of-life data. + * Provides classes for representing and working with tree-of-life data. */ // Represents a tree-of-life node/tree @@ -13,7 +13,7 @@ export class TolNode { this.parent = parent; } } -// Represents a tree-of-life node obtained from tol.json +// Represents a tree-of-life node obtained from tolData.json export class TolNodeRaw { name: string; children?: TolNodeRaw[]; @@ -29,15 +29,14 @@ export function tolFromRaw(node: TolNodeRaw): TolNode { if (node.children == null){ tolNode.children = []; } else { - tolNode.children = Array(node.children.length); - node.children.forEach((child, idx) => {tolNode.children[idx] = helper(child, tolNode)}); + tolNode.children = node.children.map(child => helper(child, tolNode)); } tolNode.parent = parent; return tolNode; } return helper(node, null); } -// Returns a mapping from TolNode names to TolNodes in a given tree +// Returns a map from TolNode names to TolNodes in a given tree export function getTolMap(tolTree: TolNode): Map<string, TolNode> { function helper(node: TolNode, map: Map<string, TolNode>){ map.set(node.name, node); |
