-
Notifications
You must be signed in to change notification settings - Fork 1.7k
add task solution #1742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
add task solution #1742
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,21 @@ const food = { | |
| const tree = document.querySelector('#tree'); | ||
|
|
||
| function createTree(element, data) { | ||
| // WRITE YOUR CODE HERE | ||
| const ul = document.createElement('ul'); | ||
|
|
||
| element.appendChild(ul); | ||
|
Comment on lines
+28
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
|
|
||
| for (const key in data) { | ||
| const li = document.createElement('li'); | ||
|
|
||
| li.textContent = key; | ||
|
|
||
| if (typeof data[key] === 'object' && data[key] !== null) { | ||
| createTree(li, data[key]); | ||
| } | ||
|
|
||
| ul.appendChild(li); | ||
| } | ||
| } | ||
|
|
||
| createTree(tree, food); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
<ul>element is created unconditionally. Consider what happens whencreateTreeis called recursively with an emptydataobject, like for theWineorCherryproperties. This results in an extra, empty<ul>being added for leaf nodes. A list should only be created if there are items to display in it.