Skip to content

solution - #2067

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

solution#2067
kristinakovalchuk wants to merge 3 commits into
mate-academy:masterfrom
kristinakovalchuk:develop

Conversation

@kristinakovalchuk

Copy link
Copy Markdown
- [DEMO LINK](https://kristinakovalchuk.github.io/js_task_parse_list_DOM/)

@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 implementation has three critical blockers that must be fixed:

  1. Incomplete employee schema (line ~19): The getEmployees function returns {name, salary} but the task requires {name, position, salary, age}. You need to extract position and age from the list item's content.

  2. Missing required helper function: The task explicitly requires a parseSalary or similar helper function to convert salary strings to numbers, but the code uses inline Number(...) conversions instead. Extract this into a reusable function that both sortList and getEmployees can use.

  3. Bug: wrong variable used (line ~19): Uses global list instead of the parameter listElement. Should be Array.from(listElement.children) to match how sortList uses its parameter.

  4. Test failure: The should be sorted by salary DSC test is failing (expected 10, got 5), indicating the sorting functionality is broken. The salary values aren't being sorted in descending order correctly.

Please address these issues before resubmitting.


✨ 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 +18 to +24
function getEmployees(listElement) {
return Array.from(list.children).map((li) => {
return {
name: li.textContent.trim(),
salary: Number((li.dataset.salary || '').replace(/,/g, '')),
};
});

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 employee object only returns {name, salary}, but the task requires schema {name, position, salary, age}. You need to extract position and age from the list item's content and include them in the returned object.

Comment thread src/scripts/main.js Outdated
Comment on lines +7 to +8
const salaryA = Number((a.dataset.salary || '').replace(/,/g, ''));
const salaryB = Number((b.dataset.salary || '').replace(/,/g, ''));

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 helper function to convert salary string to number. Currently the conversion logic is duplicated inline. Extract this into a separate parseSalary or similar helper function that both sortList and getEmployees can use.

Comment thread src/scripts/main.js Outdated
}

function getEmployees(listElement) {
return Array.from(list.children).map((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.

Bug: Uses global list variable instead of the function parameter listElement. Should be Array.from(listElement.children) to be consistent with how sortList uses its parameter.

@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 a core requirement is missing and tests are failing. The task requires a reusable helper to parse salaries, but the code currently parses salaries inline in multiple places (e.g., around lines 7-8 and 23) and uses inconsistent regex patterns ([$,] vs ,). This inconsistency can lead to incorrect numeric values and breaks the requirement for a single helper function. Additionally, the Cypress test “Parse list app — should be sorted by salary DSC” fails, indicating the list is not properly sorted in descending numeric order—likely due to improper or inconsistent salary parsing.

Critical issues to fix:

  • Implement a shared parseSalary helper (e.g., parseSalary(str)) that strips currency symbols/commas and converts to a number, and use it in both sortList and getEmployees to ensure consistent parsing. For example: Number((str || '').replace(/[^ \d.-]/g, '')) or at least remove [$,] consistently.
  • Ensure sorting uses numeric comparison with the parsed salaries and orders by descending: items.sort((a, b) => parseSalary(b) - parseSalary(a)). Verify all list items are re-appended in the correct order and the full length remains intact.

Minor: If salaries can include symbols or spaces, make the helper robust by removing all non-numeric characters except sign/decimal. Great job on handling descending logic conceptually and returning complete employee objects—once the helper is added and used consistently, the tests should pass. Keep going—you’re close!


✨ 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 +7 to +8
const salaryA = Number((a.dataset.salary || '').replace(/,/g, ''));
const salaryB = Number((b.dataset.salary || '').replace(/,/g, ''));

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 helper function for parsing salary (string to number conversion). Currently salary parsing is done inline with Number((a.dataset.salary || '').replace(/,/g, '')). Extract this into a reusable parseSalary function that both sortList and getEmployees can call.

Comment thread src/scripts/main.js Outdated
return {
name: li.textContent.trim(),
position: li.dataset.position,
salary: Number((li.dataset.salary || '').replace(/[$,]/g, '')),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Salary parsing is duplicated inline. Also note the regex differs from line 23: [$,] vs ,. A helper function would ensure consistent parsing.

@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 implementation is complete and correct. The shared parseSalary helper is properly implemented and used consistently in both sortList and getEmployees, ensuring clean, maintainable code. The descending sort correctly uses numeric comparison, and all employee objects include the required name, position, salary, and age fields. Great work resolving the previous issues and following the schema requirements. Keep this pattern of extracting reusable logic into helper functions - it makes your code more testable and easier to maintain.


✨ 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