Skip to content

Commit 7da6078

Browse files
authored
Added questions 21 to 30 in faq_js.mdx (sadanandpai#69)
* Update dom.mdx
1 parent c20e62c commit 7da6078

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

web/src/pages/challenges/dom.mdx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -368,20 +368,19 @@ function cloneDOMTree(root) {
368368

369369
```js copy
370370
/**
371-
* @param {HTMLElement | null} tree
372-
* @return {number}
371+
* Counts all child elements in a DOM tree.
372+
*
373+
* @param {HTMLElement | null} root - The root element from which to start counting.
374+
* @return {number} - The total number of child elements.
373375
*/
374376
function countElements(root) {
375377
if (!root) return 0;
376378

377-
let count = 1; // Count this element
379+
let count = 1;
378380

379-
if (root.hasChildNodes()) {
380-
for (let child of root.children) {
381-
count += countElements(child);
382-
}
381+
for (let child of root.children) {
382+
count += countElements(child);
383383
}
384-
385384
return count;
386385
}
387386
```

0 commit comments

Comments
 (0)