Skip to content

solution - #2066

Open
yevhen-dts wants to merge 2 commits into
mate-academy:masterfrom
yevhen-dts:develop
Open

solution#2066
yevhen-dts wants to merge 2 commits into
mate-academy:masterfrom
yevhen-dts:develop

Conversation

@yevhen-dts

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 via firstElement.append(...sortList(listItems)); calling sortList(listItems) again does work twice and can create confusion.
  • Align sortList with 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 so sortList(list) handles appending internally.
  • Convert salary to a number in getEmployees. The schema requires a numeric salary, but you currently return the string from dataset.salary. Parse it using the same logic as your salary helper.
  • After sorting, call getEmployees with the current, sorted list items (e.g., firstElement.children or firstElement.querySelectorAll('li')) instead of the original listItems NodeList captured before sorting, so the resulting array reflects the sorted order.

Minor suggestions:

  • Make getSalary more defensive in case data-salary is missing (e.g., default to empty string before replace).
  • Optionally rename firstElement to something clearer like employeesList for 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. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread src/scripts/main.js
@@ -1,3 +1,32 @@
'use strict';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread src/scripts/main.js Outdated
Comment on lines +18 to +31
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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/scripts/main.js
Comment on lines +7 to +11
function getSalary(employee) {
const salaryStr = employee.getAttribute('data-salary').replace(',', '');
const salary = +salaryStr.replace('$', '');

return salary;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/scripts/main.js Outdated
Comment on lines +14 to +18
function sortList(list) {
return Array.from(list).sort((a, b) => getSalary(b) - getSalary(a));
}

firstElement.append(...sortList(listItems));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread src/scripts/main.js Outdated
Comment on lines +20 to +26
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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread src/scripts/main.js Outdated
Comment on lines +18 to +32
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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 getSalary defensive when data-salary is missing to avoid a potential .replace on undefined (e.g., const salaryStr = (employee.dataset.salary || '').replace(',', '')).
  • Align the API of getEmployees with the spec by passing the list element (e.g., getEmployees(employeesList)) and iterating its querySelectorAll('li') internally; your current approach still works since you query after sorting.
  • Confirm there’s no leftover duplicate sortList call 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

  1. Rate AI review example

Comment thread src/scripts/main.js
const employeesList = document.body.querySelector('ul');

function getSalary(employee) {
const salaryStr = employee.dataset.salary.replace(',', '');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(',', '')).

Comment thread src/scripts/main.js
});
}

sortList(employeesList);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/scripts/main.js
}

sortList(employeesList);
getEmployees(employeesList.querySelectorAll('li'));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/scripts/main.js
return {
name: employee.dataset.name,
position: employee.dataset.position,
salary: getSalary(employee),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: employeesList variable name is clear — good. Ensure getEmployees returns salary as a number (it does via getSalary) — correct. No other functional issues found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants