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
34 changes: 33 additions & 1 deletion src/scripts/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
'use strict';

// write code here
const employeeList = document.querySelector('ul');

function getSalaryNumber(salary) {
return Number(salary.replaceAll(',', '').replace('$', ''));
}

function sortList(list) {
const items = [...list.children];

items.sort((a, b) => {
const salaryA = getSalaryNumber(a.dataset.salary);
const salaryB = getSalaryNumber(b.dataset.salary);

return salaryB - salaryA;
});

list.append(...items);
}

function getEmployees(list) {
const items = [...list.children];

return items.map((item) => ({
name: item.textContent.trim(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For the name field you currently use item.textContent.trim(). Depending on the HTML structure, this may include position or other text; if the task expects the name from a specific data attribute (like data-name), you should read from that dataset property instead to match the "right objects" schema exactly.

position: item.dataset.position,
salary: getSalaryNumber(item.dataset.salary),
age: Number(item.dataset.age),
}));
}

sortList(employeeList);

getEmployees(employeeList);
Loading