-
Notifications
You must be signed in to change notification settings - Fork 1.9k
completed the task #1920
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?
completed the task #1920
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,52 @@ | ||
| 'use strict'; | ||
|
|
||
| // write code here | ||
| const li = document.querySelectorAll('li'); | ||
| const father = li[0].parentNode; | ||
|
|
||
| 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. |
||
| const resultList = Array.from(list).sort((firstPerson, secondPerson) => { | ||
| const firstPersonSalary = parseSalary(firstPerson.dataset.salary, 'salary'); | ||
| const secondPersonSalary = parseSalary( | ||
| secondPerson.dataset.salary, | ||
| 'salary', | ||
| ); | ||
|
|
||
| return secondPersonSalary - firstPersonSalary; | ||
|
Comment on lines
+7
to
+14
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 comparator calls |
||
| }); | ||
|
|
||
| for (const result of resultList) { | ||
| if (father) { | ||
| father.append(result); | ||
|
Comment on lines
+17
to
+19
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. |
||
| } | ||
| } | ||
|
|
||
| return resultList; | ||
| } | ||
|
|
||
| function getEmployees(list) { | ||
| const arraysPersons = []; | ||
|
|
||
| for (const oneLi of list) { | ||
| arraysPersons.push({ | ||
| name: oneLi.textContent, | ||
|
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. Using 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. Using |
||
| position: oneLi.dataset.position, | ||
| salary: parseSalary(oneLi.dataset.salary, 'salary'), | ||
| age: parseSalary(oneLi.dataset.age, 'age'), | ||
|
Comment on lines
+33
to
+34
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. |
||
| }); | ||
| } | ||
|
|
||
| return arraysPersons; | ||
| } | ||
|
|
||
| sortList(li); | ||
| getEmployees(sortList(li)); | ||
|
Comment on lines
+41
to
+42
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. Calling |
||
|
|
||
| function parseSalary(str, what) { | ||
| if (what === 'salary') { | ||
| return Number(str.slice(1).split(',').join('.')); | ||
|
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. Current salary normalization ( |
||
| } | ||
|
|
||
| if (what === 'age') { | ||
| return Number(str); | ||
| } | ||
| } | ||
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.
Deriving
fatherfromli[0]at module scope is unsafe when the NodeList might be empty and also couples code to a global variable. Compute the parent element insidesortListfrom the passedlist(e.g.const parent = list[0]?.parentElement) and return early if missing. This addresses checklist items #11 and #12.