Repository navigation
solution #2095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
solution #2095
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,39 @@ | ||
| 'use strict'; | ||
|
|
||
| // write code here | ||
|
|
||
| const ul = document.querySelector('ul'); | ||
| const lists = document.querySelectorAll('li'); | ||
|
|
||
| function sortList(list) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing required standalone helper function to convert salary string to number. The task explicitly requires a helper function for this conversion that |
||
| const items = [...list].sort((a, b) => { | ||
| const ASalary = conversionToANumber(a.dataset.salary); | ||
| const BSalary = conversionToANumber(b.dataset.salary); | ||
|
|
||
| return BSalary - ASalary; | ||
| }); | ||
|
|
||
| ul.innerHTML = ''; | ||
|
|
||
| items.forEach((item) => { | ||
| ul.append(item); | ||
| }); | ||
| } | ||
|
|
||
| function getEmployees(list) { | ||
| return [...list].map((item) => { | ||
| return { | ||
| ...item.dataset, | ||
| salary: +item.dataset.salary.slice(1).replaceAll(',', ''), | ||
| name: item.textContent, | ||
|
Comment on lines
+23
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| }; | ||
| }); | ||
|
Comment on lines
+23
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| } | ||
|
|
||
| function conversionToANumber(number) { | ||
| return +number.slice(1).replaceAll(',', ''); | ||
| } | ||
|
|
||
| getEmployees(lists); | ||
|
|
||
| sortList(lists); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
sortListfunction should take a DOM list (li elements) as parameter and sort them by extracting salary from data attributes, not receive an already-processed array. Per requirements: 'takes a list property, and sorts list items in descending order by salary from data attribute'