HardPro challengeJavaScriptTypeScript

Render Tree Walker

ReactTreesTraversal

Walk a virtual DOM tree and return all text nodes in document order.
Tree node: { type, children? } | { type: 'text', value }.

Sample tests

Test #1Single text
Input: [{"type":"div","children":[{"type":"text","value":"hi"}]}]
Output: ["hi"]
Test #2Two text siblings
Input: [{"type":"p","children":[{"type":"text","value":"a"},{"type":"text","value":"b"}]}]
Output: ["a","b"]
Test #3Empty children
Input: [{"type":"span","children":[]}]
Output: []
Test #4Mixed depths
Input: [{"type":"div","children":[{"type":"p","children":[{"type":"text","value":"deep"}]},{"type":"text","value":"shallow"}]}]
Output: ["deep","shallow"]
Test #5Root is text
Input: [{"type":"text","value":"root"}]
Output: ["root"]