We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c20e62c commit 7da6078Copy full SHA for 7da6078
1 file changed
web/src/pages/challenges/dom.mdx
@@ -368,20 +368,19 @@ function cloneDOMTree(root) {
368
369
```js copy
370
/**
371
- * @param {HTMLElement | null} tree
372
- * @return {number}
+ * Counts all child elements in a DOM tree.
+ *
373
+ * @param {HTMLElement | null} root - The root element from which to start counting.
374
+ * @return {number} - The total number of child elements.
375
*/
376
function countElements(root) {
377
if (!root) return 0;
378
- let count = 1; // Count this element
379
+ let count = 1;
380
- if (root.hasChildNodes()) {
- for (let child of root.children) {
381
- count += countElements(child);
382
- }
+ for (let child of root.children) {
+ count += countElements(child);
383
}
384
-
385
return count;
386
387
```
0 commit comments