Given an html structure that looks like the next html but has arbitrary depth. (i.e., it can go many levels deeper). Since it has an arbitrage depth, I would prefer a solution that does not require the addition of additional markup in html (e.g. classes)
<ul>
<li>branch 1
<ul>
<li>leaf 1</li>
<li>leaf 2</li>
</ul>
</li>
<li>leaf 3</li>
</ul>
How can I count all the leaves that are children for each ul? Thus, in this example, the outermost ul would have 3 sheets and two sheets nested. This seems like a recursion problem, but I can't think it through.
source
share