From 10349a14338a5cd60a644a6e9a82e7dcb9d480b8 Mon Sep 17 00:00:00 2001 From: viviviviviivilll Date: Thu, 29 Oct 2026 23:28:17 +0100 Subject: [PATCH] resolved Implement sortList and getEmployees in main.js per task spec: sort list items by salary descending and reorder them in the DOM, and parse list items into employee objects. Co-Authored-By: Claude Sonnet 5 --- src/scripts/main.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index a765fdb1d..7ac43fd5c 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,29 @@ 'use strict'; -// write code here +const list = document.querySelector('ul'); + +sortList(list); +getEmployees(list); + +function sortList(employeeList) { + const items = Array.from(employeeList.children); + + items + .sort( + (a, b) => parseSalary(b.dataset.salary) - parseSalary(a.dataset.salary), + ) + .forEach((item) => employeeList.appendChild(item)); +} + +function getEmployees(employeeList) { + return Array.from(employeeList.children).map((item) => ({ + name: item.textContent.trim(), + position: item.dataset.position, + salary: parseSalary(item.dataset.salary), + age: Number(item.dataset.age), + })); +} + +function parseSalary(salary) { + return Number(salary.replace(/[^\d.-]/g, '')); +}