Skip to content

add task solution#2014

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

add task solution#2014
ptrodion wants to merge 2 commits into
mate-academy:masterfrom
ptrodion:develop

Conversation

@ptrodion

Copy link
Copy Markdown

No description provided.

@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 the core required API is not implemented yet, which will block the task from passing. The specification explicitly requires two functions, sortList(list) and getEmployees(list), and for both of them to be called; right now the logic lives at the top level and these functions don’t exist [CHECKLIST ITEM #11, #14, #15]. getEmployees(list) must accept a list element and return an array of { name, position, salary, age } objects; you’ve built this array as a top-level constant instead of returning it from a function [CHECKLIST ITEM #2, #3]. sortList(list) must sort the actual li elements by their data-salary attribute (using your salary conversion helper) and then append those existing lis back to the list, but at the moment you sort plain objects and rebuild innerHTML, which does not meet the DOM-based requirement [CHECKLIST ITEM #1, #11, #12, #13].

To fix this, refactor so that: (1) getEmployees(list) reads list.querySelectorAll('li'), builds and returns the employee array; (2) sortList(list) converts each child li’s dataset.salary with your helper, sorts the nodes, and re-appends them to list in descending salary order; and (3) at the bottom of the file you obtain the ul via document.querySelector('ul'), then call sortList(list) and getEmployees(list). Your salary parsing helper and object shape are good starts, so once they are wired into these two functions and used on the actual DOM elements, you should be in line with the task requirements. Keep going—you’re close, and this refactor will make your solution both cleaner and compliant with the spec.


✨ 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 Outdated
'use strict';

// write code here
const elementParent = document.querySelector('ul');

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 task requires encapsulating logic into a sortList(list) function and a getEmployees(list) function that are both called, instead of doing work at the top level; you should refactor so this query is used inside those functions and they accept list as a parameter (checklist items #11, #14, #15).

Comment thread src/scripts/main.js
Comment on lines +7 to +12
const parseSalary = (salaryStr) => {
if (!salaryStr) {
return 0;
}

return Number(salaryStr.replace(/[^0-9.]/g, '')) || 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This helper for converting salary strings to numbers fits the requirement to write a conversion helper, but it should be used inside a sortList(list) function that sorts actual li elements by their data-salary attribute (checklist items #11 and #13).

Comment thread src/scripts/main.js Outdated
Comment on lines +15 to +25
const arrayListOfEmployees = elemListOfEmployees.map((employee) => {
const { position, salary, age } = employee.dataset;
const employeeName = employee.textContent.trim();

return {
name: employeeName,
position,
salary,
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.

This mapping correctly builds employee objects, but it must be moved into a getEmployees(list) function that takes a list and returns this array, rather than creating a top-level constant (checklist items #2, #3, and #14).

Comment thread src/scripts/main.js Outdated
Comment on lines +27 to +29
const sortedBySalary = arrayListOfEmployees.sort(
(a, b) => parseSalary(b.salary) - parseSalary(a.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.

Sorting the array of objects by salary is conceptually correct, but according to the task, sortList should sort the list items (li elements) themselves and re-append them to the list, not just sort a separate array of objects (checklist items #1, #11, and #12).

Comment thread src/scripts/main.js Outdated
Comment on lines +31 to +45
const newListHTML = sortedBySalary
.map((user) => {
return `
<li
data-position="${user.position}"
data-salary="${user.salary}"
data-age="${user.age}"
>
${user.name}
</li>
`;
})
.join('');

elementParent.innerHTML = newListHTML;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Rebuilding innerHTML with a template works visually, but the requirement is to have a sortList(list) function that appends sorted existing items back to the list; consider performing DOM-based reordering instead and exposing this via the required function API (checklist item #12 and #11).

@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 your solution because it cleanly meets all of the specified functional requirements. Your sortList(list) function correctly reads the existing li elements from the provided list, parses the data-salary via a helper, sorts them in descending salary order, and re-appends the same DOM nodes rather than rebuilding the list, which aligns with the DOM-focused requirement. Your getEmployees(list) function uses list.querySelectorAll('li') and returns an array of objects with the required shape { name, position, salary, age }, correctly extracting data attributes and text content. Both functions are called after selecting the ul from the document, so the overall flow (find the list, sort it, and then build the employees array) matches the task steps. The helper salary parser is a nice touch for robustness and keeps your main functions clear. Overall, the implementation is concise, readable, and should work well with the automated tests and the given specification.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

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