Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion src/scripts/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
'use strict';

// write code here
const liElements = [...document.querySelectorAll('li')];

function sortList(list) {
const ul = list[0].parentNode;
const sortProperty = 'salary';

list.sort(
(li1, li2) =>
strToNumber(li2.dataset[sortProperty]) -
strToNumber(li1.dataset[sortProperty]),
);

list.forEach((li) => ul.append(li));
}

function strToNumber(str) {
return Number(str.replace(/[$,]/g, ''));
}

function getEmployees(list) {
const employees = [];

for (const li of list) {
const employee = {
name: li.textContent.trim(),
position: li.dataset.position,
salary: strToNumber(li.dataset.salary),
age: Number(li.dataset.age),
};

employees.push(employee);
}

return employees;
Comment on lines +22 to +36

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 getEmployees function should return objects matching the schema: { name, position, salary, age }. Currently the returned objects include name, salary, and age, but position is missing. Extract the position value from the list item's text content (e.g., using querySelector or textContent parsing).

}

sortList(liElements);
getEmployees(liElements);
Loading