feat: function that can create tree from its given object#1709
feat: function that can create tree from its given object#1709dmytro-halieba wants to merge 1 commit intomate-academy:masterfrom
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great job on implementing the createTree function! Your recursive solution is clean, well-structured, and meets all the requirements of the task, so I am happy to approve it.
As a point of improvement for future projects, consider making your for...in loop more robust. This loop can sometimes iterate over inherited properties from an object's prototype. You can prevent this by adding a check inside the loop, like this:
if (Object.prototype.hasOwnProperty.call(data, key)) {
// your code here
}This is a best practice that makes your code safer. Overall, excellent work on this submission!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| // WRITE YOUR CODE HERE | ||
| const ul = document.createElement('ul'); | ||
|
|
||
| for (const key in data) { |
There was a problem hiding this comment.
The for...in loop iterates over all enumerable properties of an object, including those inherited from its prototype. This can sometimes lead to unexpected items in your list. To make your code more robust, it's a good practice to check if the property is directly on the object. You can do this by adding a condition like if (Object.prototype.hasOwnProperty.call(data, key)) { ... } inside your loop.
DEMO LINK