feat: sorting list of people by their salary#1925
feat: sorting list of people by their salary#1925dmytro-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
Good job implementing the visual sorting of the employee list! The logic works correctly. However, this requires changes because the getEmployees function doesn't meet a core requirement from the task description. It should return an array of JavaScript objects, each with name, position, salary, and age properties, but it currently returns an array of DOM elements.
Please modify the function to iterate over the list items, create an object for each one, and extract the necessary data from its text and data-* attributes. You're very close to completing the task!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| function getEmployees() { | ||
| const collection = document.getElementsByTagName('li'); | ||
| const list = []; | ||
|
|
||
| for (let i = 0; i < collection.length; i++) { | ||
| list.push(collection.item(i)); | ||
| } | ||
|
|
||
| return list; | ||
| } |
There was a problem hiding this comment.
This function does not meet the requirements from the task description (Step 3). It should accept a list of DOM elements as an argument and return an array of JavaScript objects, where each object represents an employee with name, position, salary, and age properties. The current implementation returns an array of DOM elements instead.
| const salary1 = salaryNormilaze(employee1['attributes']['data-salary']['value']); | ||
| const salary2 = salaryNormilaze(employee2['attributes']['data-salary']['value']); |
There was a problem hiding this comment.
This works for getting the salary value. As a suggestion for cleaner code, you can use the dataset property to access data-* attributes directly, for example: employee1.dataset.salary.
| for (let i = 0; i < sortedList.length; i++) { | ||
| document.getElementsByTagName('li')[i].outerHTML = sortedList[i].outerHTML; | ||
| } |
There was a problem hiding this comment.
The task requires you to 'Append sorted items to list'. This code replaces the HTML of existing elements. A more direct and safer way to meet this requirement is to get the parent <ul> container, clear its current content (e.g., ul.innerHTML = ''), and then loop through your sortedList array, appending each <li> element using ul.appendChild(li).
DEMO LINK