solution - #2066
Conversation
yevhen-dts
commented
Sep 3, 2026
- DEMO LINK
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am requesting changes because there are a couple of critical issues that affect correctness and task alignment.
Critical issues to fix:
- Remove the duplicate call to
sortList(at/around line 31). You already append the sorted nodes viafirstElement.append(...sortList(listItems)); callingsortList(listItems)again does work twice and can create confusion. - Align
sortListwith the task requirement: it should accept the list element and both sort and append the items to that list. Right now it returns a sorted array and the append happens outside, which diverges from the spec. Refactor sosortList(list)handles appending internally. - Convert
salaryto a number ingetEmployees. The schema requires a numericsalary, but you currently return the string fromdataset.salary. Parse it using the same logic as your salary helper. - After sorting, call
getEmployeeswith the current, sorted list items (e.g.,firstElement.childrenorfirstElement.querySelectorAll('li')) instead of the originallistItemsNodeList captured before sorting, so the resulting array reflects the sorted order.
Minor suggestions:
- Make
getSalarymore defensive in casedata-salaryis missing (e.g., default to empty string before replace). - Optionally rename
firstElementto something clearer likeemployeesListfor readability.
You’re very close—once these are addressed, the implementation should meet the requirements cleanly and efficiently.
✨ 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
| @@ -1,3 +1,32 @@ | |||
| 'use strict'; | |||
There was a problem hiding this comment.
Requirement: Replace <your_account> in README link — this is a task-level requirement, not code. Ensure you updated the demo link elsewhere (not in this file).
| firstElement.append(...sortList(listItems)); | ||
|
|
||
| function getEmployees(list) { | ||
| return Array.from(list).map((value) => { | ||
| return { | ||
| name: value.dataset.name, | ||
| position: value.dataset.position, | ||
| salary: value.dataset.salary, | ||
| age: +value.dataset.age, | ||
| }; | ||
| }); | ||
| } | ||
|
|
||
| sortList(listItems); |
There was a problem hiding this comment.
Minor correctness: firstElement.append(...sortList(listItems)); uses listItems (a static NodeList) which is fine here, but later sortList(listItems); is called again (line 31) — that second call is redundant because you already appended the sorted nodes. Remove the duplicate call to sortList at line 31 to avoid doing work twice.
| function getSalary(employee) { | ||
| const salaryStr = employee.getAttribute('data-salary').replace(',', ''); | ||
| const salary = +salaryStr.replace('$', ''); | ||
|
|
||
| return salary; |
There was a problem hiding this comment.
The helper getSalary strips comma and dollar sign correctly but uses employee.getAttribute('data-salary') instead of employee.dataset.salary — that's acceptable. However if getAttribute returns null it will throw; tests likely assume the attribute exists. Still, consider using const salaryStr = (employee.dataset.salary || '').replace(',', ''); to be more robust.
| function sortList(list) { | ||
| return Array.from(list).sort((a, b) => getSalary(b) - getSalary(a)); | ||
| } | ||
|
|
||
| firstElement.append(...sortList(listItems)); |
There was a problem hiding this comment.
The sortList function currently returns a sorted array of nodes but does not itself append the items; you append them by calling firstElement.append(...sortList(listItems)); which couples sortList with a particular firstElement variable. The task description expects sortList to take a list property and append sorted items to that list. To follow that exactly, move the append into sortList so the function both sorts and appends to the provided list element (or document list).
| function getEmployees(list) { | ||
| return Array.from(list).map((value) => { | ||
| return { | ||
| name: value.dataset.name, | ||
| position: value.dataset.position, | ||
| salary: value.dataset.salary, | ||
| age: +value.dataset.age, |
There was a problem hiding this comment.
The getEmployees function returns salary as the raw string from dataset.salary. The task schema requires salary to be a number (see schema: { name, position, salary, age } and instruction that salary from data attribute is a string — convert it to number). Convert salary to a Number (use the same parsing logic as getSalary).
| firstElement.append(...sortList(listItems)); | ||
|
|
||
| function getEmployees(list) { | ||
| return Array.from(list).map((value) => { | ||
| return { | ||
| name: value.dataset.name, | ||
| position: value.dataset.position, | ||
| salary: value.dataset.salary, | ||
| age: +value.dataset.age, | ||
| }; | ||
| }); | ||
| } | ||
|
|
||
| sortList(listItems); | ||
| getEmployees(listItems); |
There was a problem hiding this comment.
At the end you call getEmployees(listItems); — after sorting you should pass the actual (now-sorted) list items. If you change sortList to append to the list element and then call getEmployees(firstElement.querySelectorAll('li')) or getEmployees(firstElement.children), it will produce employees in the sorted order. Update the call to pass the currently-present list items rather than the original NodeList captured before sorting.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am approving this submission because the core requirements are met: the list is sorted in descending salary order, getEmployees returns correctly structured objects with numeric salary and age, and both functions are called as required. Nice job keeping sortList(list) responsible for sorting and appending items back into the list, and using a helper to parse salary.
Minor improvements to consider (non-blocking):
- Make
getSalarydefensive whendata-salaryis missing to avoid a potential.replaceonundefined(e.g.,const salaryStr = (employee.dataset.salary || '').replace(',', '')). - Align the API of
getEmployeeswith the spec by passing the list element (e.g.,getEmployees(employeesList)) and iterating itsquerySelectorAll('li')internally; your current approach still works since you query after sorting. - Confirm there’s no leftover duplicate
sortListcall anywhere else in the codebase.
Overall, solid implementation—just a couple of robustness and API-alignment tweaks you could make next time.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| const employeesList = document.body.querySelector('ul'); | ||
|
|
||
| function getSalary(employee) { | ||
| const salaryStr = employee.dataset.salary.replace(',', ''); |
There was a problem hiding this comment.
The requirement and previous feedback ask that getSalary be more defensive if data-salary is missing. Line 6 assumes employee.dataset.salary exists and calls .replace on it which will throw if it's undefined. Consider defaulting to an empty string before calling replace (for example: const salaryStr = (employee.dataset.salary || '').replace(',', '')).
| }); | ||
| } | ||
|
|
||
| sortList(employeesList); |
There was a problem hiding this comment.
The sortList implementation meets the requirement to accept a list element and append sorted items to the list, but the earlier review flagged a duplicate call to sortList. Currently the file calls sortList(employeesList) once (line 34) — that is fine. If there is any leftover duplicate call elsewhere remove it. No change required here if no duplicate exists.
| } | ||
|
|
||
| sortList(employeesList); | ||
| getEmployees(employeesList.querySelectorAll('li')); |
There was a problem hiding this comment.
When calling getEmployees you should pass the sorted list items so the returned array reflects the sorted order. Currently you call getEmployees(employeesList.querySelectorAll('li')) (line 35) which will work because querySelectorAll('li') is taken after sorting. This is acceptable; however the task description expects getEmployees to accept the list (the list element) as its argument. Consider calling getEmployees(employeesList) and adjusting getEmployees to iterate over list.querySelectorAll('li') or children to match the spec more closely.
| return { | ||
| name: employee.dataset.name, | ||
| position: employee.dataset.position, | ||
| salary: getSalary(employee), |
There was a problem hiding this comment.
Minor: employeesList variable name is clear — good. Ensure getEmployees returns salary as a number (it does via getSalary) — correct. No other functional issues found.