added solution#2024
Conversation
ParamooreXO
commented
Jul 9, 2026
- DEMO LINK
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am requesting changes because several core requirements of the task are not yet implemented, and this is causing functional test failures. The required functions sortList(list) and getEmployees(list) are missing, and your current logic works only with a global employees array instead of receiving and operating on a specific list element from the DOM. As a result, the <li> elements in the list are never reordered in the DOM, so the list is not actually sorted by salary in descending order, which directly breaks the Cypress test that checks the sorted list. In addition, salary values are kept as strings and converted inline with regex instead of using a dedicated helper function that returns a numeric salary, which the task explicitly asks for. To fix this, you should: (1) select the list element from the document, (2) implement sortList(list) to collect its <li> children, sort them by numeric salary using a helper like parseSalary(value), and append them back to the same list in sorted order, and (3) implement getEmployees(list) to return an array of { name, position, salary, age } with salary as a number. Once these functions are defined, called with the list element, and the DOM nodes are reordered rather than just rewriting dataset and text content, your solution will align with the requirements and should pass the failing test. You did a good job using dataset and building employee objects with the right keys, so reusing that approach inside the new functions will help you complete the task correctly.
✨ 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
| 'use strict'; | ||
|
|
||
| // write code here | ||
| const employees = []; |
There was a problem hiding this comment.
The task requires you to obtain the list element from the document and then pass it into the required functions; here you are only creating a global employees array and not working with a specific list node as described.
| // write code here | ||
| const employees = []; | ||
|
|
||
| document.querySelectorAll('[data-salary]').forEach((listItem) => { |
There was a problem hiding this comment.
Instead of directly iterating all [data-salary] elements, the specification asks for sortList(list) and getEmployees(list) functions, so this logic should be moved into those functions and operate on the list argument.
| name: listItem.textContent.trim(), | ||
| position: listItem.dataset.position, | ||
| salary: listItem.dataset.salary, |
There was a problem hiding this comment.
According to the requirements, salary should be converted to a number via a helper function; here you keep the salary as a string taken directly from dataset.salary.
| }); | ||
| }); | ||
|
|
||
| employees.sort((a, b) => { |
There was a problem hiding this comment.
The sorting logic must be encapsulated in a sortList(list) function that works on the list’s items, not on a separate employees array; also, the salary-to-number conversion should be done in a helper instead of inline regex replacement.
| }); | ||
|
|
||
| employees.sort((a, b) => { | ||
| return b.salary.replace(/[^0-9]/g, '') - a.salary.replace(/[^0-9]/g, ''); |
There was a problem hiding this comment.
The sort comparator uses replace on b.salary twice and never on a.salary, which looks like a copy‑paste mistake and will not correctly compute the difference between b and a salaries.
| return b.salary.replace(/[^0-9]/g, '') - a.salary.replace(/[^0-9]/g, ''); | ||
| }); | ||
|
|
||
| document.querySelectorAll('li[data-salary]').forEach((listItem, index) => { |
There was a problem hiding this comment.
Rewriting dataset values and text content does not change the order of <li> elements, but the requirement is to sort the list by salary by reordering the list items in the DOM and appending them back to the list.
|
|
||
| document.querySelectorAll('li[data-salary]').forEach((listItem, index) => { | ||
| listItem.dataset.position = `${employees[index].position}`; | ||
| listItem.dataset.salary = `$${employees[index].salary}`; |
There was a problem hiding this comment.
Adding a $ prefix when writing back dataset.salary changes the format of the data attribute in a way not requested; the attribute should remain a clean data value, while formatting belongs in display, not the dataset.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am requesting changes because there is still a critical mismatch with the task’s explicit requirements around salary handling and the helper function. The instructions require a dedicated helper (e.g., parseSalary(value)) to convert the salary data attribute from string to number, but right now the conversion is done inline with regex in sortList (around line 7) and duplicated again for bValue, which violates the requirement for a reusable helper. Additionally, in getEmployees (later in src/scripts/main.js), the salary field of the returned employee objects is kept as the original dataset.salary string, while the spec clearly states that salary must be numeric. These issues are critical because they directly break checklist items that define the expected API shape of getEmployees and the mandatory helper function.
To fix this, introduce a small helper like function parseSalary(value) { /* convert "50 000 ₽" to 50000 */ } once at the top of main.js, and then use it both in sortList for comparing salaries and in getEmployees when building each employee object. Make sure that after calling parseSalary, employee.salary is a number (e.g., 50000, not '50 000 ₽'), and remove any duplicated inline regex logic so all salary parsing goes through that helper. As a minor improvement, you could have getEmployees accept the <ul> element and access .children inside, aligning more closely with the original function signature, but this is optional compared to the salary issues. Once you add the helper and ensure numeric salaries everywhere, your solution will fully meet the functional and checklist requirements, and you’re otherwise very close to a complete, correct implementation.
✨ 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 sortList(li) { | ||
| li.sort((a, b) => { | ||
| const aValue = a.dataset.salary.replace(/[^0-9]/g, ''); |
There was a problem hiding this comment.
| function sortList(li) { | ||
| li.sort((a, b) => { | ||
| const aValue = a.dataset.salary.replace(/[^0-9]/g, ''); | ||
| const bValue = b.dataset.salary.replace(/[^0-9]/g, ''); |
There was a problem hiding this comment.
Similarly to line 7, this inline conversion for bValue should be handled by the same helper function that parses the salary string to a number, instead of duplicating the regex here.
| function getEmployees(li) { | ||
| return li.map((item) => { | ||
| const position = item.dataset.position; | ||
| const salary = item.dataset.salary; |
There was a problem hiding this comment.
In getEmployees, salary is taken directly from dataset.salary and kept as a string, but the requirements specify that the employee object’s salary must be a number. Use the same salary-parsing helper here so salary is numeric in the returned objects.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your solution is approved. You correctly locate the <ul> element, build an array from its <li> children, then use sortList(list) to sort employees by salary in descending order and getEmployees(list) to construct objects with { name, position, salary, age }, which matches the task requirements. The dedicated parseSalary(value) helper cleanly handles salary conversion and is reused in both main functions, which is a nice improvement in terms of code reuse and clarity.
A small improvement opportunity is to make the numeric intent of parseSalary more explicit by returning Number(cleanedDigits) or parseInt(cleanedDigits, 10) instead of relying on implicit coercion in arithmetic operations; this will make your code more self-explanatory to readers. Overall, your implementation is focused, readable, and stays within the required scope of changing only main.js. Well done on addressing the previous review points and delivering a solid, maintainable solution.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨