Skip to content

Task completed - #2051

Open
VladyslavL02 wants to merge 3 commits into
mate-academy:masterfrom
VladyslavL02:develop
Open

Task completed#2051
VladyslavL02 wants to merge 3 commits into
mate-academy:masterfrom
VladyslavL02:develop

Conversation

@VladyslavL02

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

This code has critical blockers that must be fixed before it can work. The task requires a sortList function that takes a list parameter and a getEmployees function that returns an array of employee objects with {name, position, salary, age} properties - both of these are completely missing. Additionally, line 6 removes all elements before processing, which empties the collection and causes the loop on line 9 to iterate over nothing, so the sorting logic never executes. You need to: (1) Create the sortList function that accepts a list parameter, (2) Create the getEmployees function that extracts employee data from element.dataset.name, element.dataset.position, element.dataset.salary, and element.dataset.age to build the employee objects, and (3) Fix the element removal logic so elements are processed before being cleared. Please review the task requirements and implement these functions as specified.


✨ 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
Comment on lines +3 to +24
const elements = document.querySelectorAll('[data-salary]');
const elementsParent = [...elements][0].parentElement;

elements.forEach((element) => element.remove());

const peopleBySalary = [];

[...elements].forEach((element) => {
const salaryValue = element.getAttribute('data-salary');

const salary = getTotalSalary(salaryValue);

peopleBySalary.push([salary, element]);
});

peopleBySalary.sort((value1, value2) => {
return value2[0] - value1[0];
});

peopleBySalary.forEach((person, index) => {
elementsParent.appendChild(peopleBySalary[index][1]);
});

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 a function named sortList that takes a list parameter. This code doesn't define sortList at all - it uses global variables instead. Define the function as specified in the requirements.

Comment thread src/scripts/main.js Outdated
Comment on lines +3 to +24
const elements = document.querySelectorAll('[data-salary]');
const elementsParent = [...elements][0].parentElement;

elements.forEach((element) => element.remove());

const peopleBySalary = [];

[...elements].forEach((element) => {
const salaryValue = element.getAttribute('data-salary');

const salary = getTotalSalary(salaryValue);

peopleBySalary.push([salary, element]);
});

peopleBySalary.sort((value1, value2) => {
return value2[0] - value1[0];
});

peopleBySalary.forEach((person, index) => {
elementsParent.appendChild(peopleBySalary[index][1]);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CRITICAL: The task requires a getEmployees function that returns an array of employee objects with {name, position, salary, age}. This function is completely missing. You must create it to pass the tests.

Comment thread src/scripts/main.js Outdated
const elements = document.querySelectorAll('[data-salary]');
const elementsParent = [...elements][0].parentElement;

elements.forEach((element) => element.remove());

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 line removes all elements before processing them. After line 6, elements becomes empty, so the loop on line 9 (using [...elements]) iterates over nothing. This causes the sorting logic to never execute.

Comment thread src/scripts/main.js Outdated
Comment on lines +9 to +16

[...elements].forEach((element) => {
const salaryValue = element.getAttribute('data-salary');

const salary = getTotalSalary(salaryValue);

peopleBySalary.push([salary, element]);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since elements were removed on line 6, this loop runs on an empty array. The sorting code below never actually processes any data.

Comment thread src/scripts/main.js
Comment on lines +26 to +36
function getTotalSalary(value) {
let salary = '';
const numbers = '0123456789';

value.split('').forEach((char) => {
if (numbers.includes(char)) {
salary += char;
}
});

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 salary parsing logic can be simplified. Instead of manually iterating through characters, use parseInt(value.replace(/\D/g, ''), 10) or Number(value.replace(/\D/g, '')) to extract numbers from the string.

Comment thread src/scripts/main.js
Comment on lines +26 to +36
function getTotalSalary(value) {
let salary = '';
const numbers = '0123456789';

value.split('').forEach((char) => {
if (numbers.includes(char)) {
salary += char;
}
});

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 task requires extracting employee data into an array of objects with {name, position, salary, age} properties from data attributes. Use element.dataset.name, element.dataset.position, etc. to build these objects in the getEmployees function.

@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

The getEmployees function has a critical issue where the returned employee objects are missing the required name property. According to the task requirements, the employee schema must include all four properties: name, position, salary, and age. Currently, only position, salary, and age are being extracted. To fix this, add name: element.getAttribute('data-name') to the returned object in the getEmployees function. This missing field is a core requirement that prevents the employee data structure from meeting the task specifications.


✨ 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
Comment on lines +42 to +47
return [...employeeElements].map((element) => {
return {
position: element.getAttribute('data-position'),
salary: getTotalSalary(element.getAttribute('data-salary')),
age: Number(element.getAttribute('data-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 returned object is missing the name property. The task requires the employee schema to include name, position, salary, and age. Add name: element.getAttribute('data-name') to the returned object.

@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

Your solution is approved. Great work implementing both sortList and getEmployees correctly and aligning with the schema by including the name property (e.g., around line 43). The salary parsing and aggregation via getTotalSalary are handled cleanly, and both functions are invoked as required.

  • What you did well:

    • Clear data transformation in getEmployees, including proper type conversion for salaries.
    • Correct sorting logic in sortList with a readable implementation.
  • Minor improvements (optional):

    • Consider adding brief inline comments explaining the intent of getTotalSalary and the sort comparator for maintainability.

Keep up the solid, clean approach—nicely done!


✨ 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