Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am requesting changes because several checklist-required behaviors are not fully met and will likely cause tests to fail.
Critical issues that must be fixed:
- In
src/scripts/main.js, the salary parsing logic is duplicated inside the sort comparator; the task explicitly requires a reusable helper likeparseSalary(str)[CHECKLIST ITEM #17]. Please extract the parsing intoparseSalary, and use it both insortListand ingetEmployees[CHECKLIST ITEM #16]. getEmployeescurrently pushessalary(andage) as raw strings fromdataset;salarymust be converted to a number using the helper, and tests may also expectageas a number [CHECKLIST ITEMS #3, #16, #19]. Also,nameis taken frominnerText, which can include extra text; instead, target only the element or text node that represents the employee’s name (or at least use a more precise selector) so thenamefield matches what tests expect.sortListappends sorted items to a globalperentvariable, and the variable name is misspelled; the function should derive the parent from the passedlist(for examplelist[0].parentElement) or accept a parent argument, and then append to that element rather than relying on a global [CHECKLIST ITEM #18].
Minor improvements (not blockers but recommended):
- Prefer
textContent.trim()overinnerTextfor consistent text extraction. - After sorting, ensure
getEmployeesuses the elements in their new sorted order (e.g., by iterating the sorted array or the list’s children) so the returned employee array order matches the visible list.
You’re very close: the overall structure and logic are on the right track, and once you add the helper, fix the data types, and remove the global parent dependency, your solution should align well with the requirements.
✨ 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
src/scripts/main.js
Outdated
| const firstPersonSalary = firstPerson.dataset.salary | ||
| .slice(1) | ||
| .split(',') | ||
| .join(''); | ||
| const secondPersonSalary = secondPerson.dataset.salary | ||
| .slice(1) | ||
| .split(',') | ||
| .join(''); |
There was a problem hiding this comment.
src/scripts/main.js
Outdated
| for (const result of resultList) { | ||
| perent.append(result); |
There was a problem hiding this comment.
sortList appends sorted items to the global perent variable rather than to the list passed as the function parameter. The checklist requires appending sorted items to the list (checklist item #18). Derive the container from the passed list (for example list[0].parentElement) or accept the parent as an argument instead of using the global variable.
src/scripts/main.js
Outdated
|
|
||
| // write code here | ||
| const li = document.querySelectorAll('li'); | ||
| const perent = document.querySelector('ul'); |
There was a problem hiding this comment.
The perent variable name appears to be a typo. Rename it to parent or, better, avoid the global and get the parent from the passed list for clarity and correctness.
src/scripts/main.js
Outdated
| arraysPersons.push({ | ||
| name: oneLi.innerText, | ||
| position: oneLi.dataset.position, | ||
| salary: oneLi.dataset.salary, | ||
| age: oneLi.dataset.age, |
There was a problem hiding this comment.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am requesting changes because there are a few critical behaviors that don’t yet meet the task requirements and will likely cause tests to fail.
Critical issues that must be fixed:
parseSalarycurrently returns a string and callers then wrap it inNumber(...). The requirement is thatparseSalaryitself returns aNumber(strip the currency symbol, remove thousands separators, normalize decimal comma, thenreturn Number(...)), and the comparator should subtract those numeric results directly.- In
getEmployees,salaryandageare kept as strings, andnameis taken fromli.textContent. Tests expectsalary(fromparseSalary) andageto be numbers, andnameto come from the specific element that holds the name (e.g.oneLi.querySelector('.name')?.textContent.trim()), so update the extraction and conversions accordingly. sortListuseslist[0].parentNodewithout guarding for an empty list, and then you callgetEmployees(li)with the originalNodeList. Derive the parent from the passedlistdefensively (e.g. computeparentandreturnearly if it’s missing), and either pass the sorted array returned fromsortListintogetEmployeesor havegetEmployeesread from the list’s parent after sorting so the employee array order matches the visible DOM order.
Minor/clean-up suggestions:
- Use
textContent.trim()consistently when reading strings from the DOM. - Prefer
parentElementoverparentNodewhen dealing with elements.
You have the main structure and helper function in place; once you adjust the types, name selection, and ordering to match these requirements, your solution should align well with the expected behavior.
✨ 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
src/scripts/main.js
Outdated
| const firstPersonSalary = parseSalary(firstPerson.dataset.salary); | ||
| const secondPersonSalary = parseSalary(secondPerson.dataset.salary); | ||
|
|
||
| return Number(secondPersonSalary) - Number(firstPersonSalary); |
There was a problem hiding this comment.
The comparator converts parsed salaries with Number(...) while parseSalary currently returns a string. Per requirements, make parseSalary return a Number so parsing logic is not duplicated and the comparator can subtract numeric values directly.
src/scripts/main.js
Outdated
|
|
||
| function sortList(list) { | ||
| const resultList = Array.from(list).sort((firstPerson, secondPerson) => { | ||
| const firstPersonSalary = parseSalary(firstPerson.dataset.salary); |
There was a problem hiding this comment.
You're calling parseSalary and then wrapping results in Number(...). Move numeric conversion into parseSalary (return a Number) and remove the extra Number(...) calls in the comparator to satisfy the helper requirement and avoid duplicated logic.
src/scripts/main.js
Outdated
| }); | ||
|
|
||
| for (const result of resultList) { | ||
| list[0].parentNode.append(result); |
There was a problem hiding this comment.
Derive the parent from the passed list instead of using list[0].parentNode directly. Also guard against an empty list (e.g. const parent = list[0] && list[0].parentElement; if (!parent) return resultList;) to avoid runtime errors.
|
|
||
| for (const oneLi of list) { | ||
| arraysPersons.push({ | ||
| name: oneLi.textContent, |
There was a problem hiding this comment.
Using oneLi.textContent for name can include other text from the li. Select the specific element that contains the name (e.g. oneLi.querySelector('.name')?.textContent.trim()) and use textContent.trim() so name matches expected test values.
src/scripts/main.js
Outdated
| name: oneLi.textContent, | ||
| position: oneLi.dataset.position, | ||
| salary: parseSalary(oneLi.dataset.salary), | ||
| age: oneLi.dataset.age, |
There was a problem hiding this comment.
age is taken as a raw string from dataset. Convert it to a number (for example age: Number(oneLi.dataset.age)) because tests expect numeric types for salary and likely age as well.
src/scripts/main.js
Outdated
| sortList(li); | ||
| getEmployees(li); |
There was a problem hiding this comment.
You call sortList(li) then getEmployees(li). querySelectorAll returns a static NodeList — pass the sorted array returned from sortList to getEmployees (for example const sorted = sortList(li); getEmployees(sorted);) or make getEmployees read elements from the list parent after sorting so the returned order matches the visible list.
src/scripts/main.js
Outdated
| getEmployees(li); | ||
|
|
||
| function parseSalary(str) { | ||
| return str.slice(1).split(',').join('.'); |
There was a problem hiding this comment.
parseSalary currently returns a modified string. Update it to return a Number (strip currency symbol, remove thousand separators, replace comma with dot if needed, then return Number(...)) so the helper fully satisfies the requirement to convert salary to a number and can be reused across functions.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am approving your solution as an educational override so you can keep progressing while you refine these concepts. You implemented all three required functions (sortList, getEmployees, parseSalary) and correctly used data-* attributes for salary, which covers several core requirements. The main things to improve are: 1) derive the parent element inside sortList from the passed list (e.g. const parent = list[0]?.parentElement) and return early if it’s missing, instead of relying on a top-level father variable [CHECKLIST ITEM #14, #25]; 2) extract the employee name from the dedicated .name element and use textContent.trim() so the object matches the expected shape [CHECKLIST ITEM #5, #24]; and 3) fix parseSalary so it removes currency symbols and thousand separators without turning "1,200" into 1.2, and always returns a Number [CHECKLIST ITEM #15, #16]. Also, call sortList only once, store the result in a variable, and pass that to getEmployees so the array order matches the sorted DOM [CHECKLIST ITEM #18]. Overall, you’re very close: the structure is right, and with these numeric parsing and DOM-handling tweaks, your solution will be both robust and test-friendly.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
|
|
||
| // write code here | ||
| const li = document.querySelectorAll('li'); | ||
| const father = li[0].parentNode; |
There was a problem hiding this comment.
Deriving father from li[0] at module scope is unsafe when the NodeList might be empty and also couples code to a global variable. Compute the parent element inside sortList from the passed list (e.g. const parent = list[0]?.parentElement) and return early if missing. This addresses checklist items #11 and #12.
| const li = document.querySelectorAll('li'); | ||
| const father = li[0].parentNode; | ||
|
|
||
| function sortList(list) { |
There was a problem hiding this comment.
| const resultList = Array.from(list).sort((firstPerson, secondPerson) => { | ||
| const firstPersonSalary = parseSalary(firstPerson.dataset.salary, 'salary'); | ||
| const secondPersonSalary = parseSalary( | ||
| secondPerson.dataset.salary, | ||
| 'salary', | ||
| ); | ||
|
|
||
| return secondPersonSalary - firstPersonSalary; |
There was a problem hiding this comment.
The comparator calls parseSalary(...) which must return numeric values. Ensure parseSalary reliably returns a Number (see the comment on line 46). Also make the comparator operate on Numbers directly (subtract numeric results) — that is already attempted but depends on correct parseSalary behavior (checklist items #15 and #16).
| for (const result of resultList) { | ||
| if (father) { | ||
| father.append(result); |
There was a problem hiding this comment.
|
|
||
| for (const oneLi of list) { | ||
| arraysPersons.push({ | ||
| name: oneLi.textContent, |
There was a problem hiding this comment.
Using oneLi.textContent for name will include other text (position/age) and may not match tests. Extract the name from the specific child (for example oneLi.querySelector('.name')?.textContent.trim()) and trim it. Tests expect name from the dedicated element and clean string (checklist item #5).
| salary: parseSalary(oneLi.dataset.salary, 'salary'), | ||
| age: parseSalary(oneLi.dataset.age, 'age'), |
| sortList(li); | ||
| getEmployees(sortList(li)); |
There was a problem hiding this comment.
Calling sortList(li); and then getEmployees(sortList(li)); runs sortList twice. Call sortList once, save its result (const sorted = sortList(li);) and then call getEmployees(sorted) (or call getEmployees on the parent’s children after sorting). This prevents duplicate DOM moves and guarantees the employee array order matches the visible list (checklist item #18 and previous-review suggestion #25).
|
|
||
| function parseSalary(str, what) { | ||
| if (what === 'salary') { | ||
| return Number(str.slice(1).split(',').join('.')); |
There was a problem hiding this comment.
Current salary normalization (str.slice(1).split(',').join('.')) converts thousand separators into a decimal point (e.g. "1,200" -> "1.200" -> 1.2), which is incorrect. Instead remove currency symbols and thousands separators, and normalize a decimal comma if present, then return Number(...). For example: const s = str.replace(/[^0-9.,-]/g, ''); const normalized = s.replace(/,/g, ''); return Number(normalized); — or implement safer logic to preserve decimal part. Ensure parseSalary always returns a Number (checklist items #15 and #16).
No description provided.