From 185ab7af2fe1b84300514add67390b96d899230b Mon Sep 17 00:00:00 2001 From: olhalutsenko Date: Tue, 10 Nov 2026 12:15:08 +0100 Subject: [PATCH] add task solution --- src/scripts/main.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index a765fdb1d..a92be15a1 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,33 @@ 'use strict'; -// write code here +const employeesList = document.querySelector('ul'); + +function getSalary(employee) { + const salary = employee.dataset.salary; + + return parseFloat(salary.replace('$', '').replace(',', '')); +} + +function sortList(list) { + const items = list.querySelectorAll('li'); + const itemsArray = Array.from(items); + + itemsArray.sort((a, b) => getSalary(b) - getSalary(a)); + + itemsArray.forEach((item) => list.appendChild(item)); +} + +function getEmployees(list) { + return Array.from(list.querySelectorAll('li')).map((item) => { + return { + name: item.textContent.trim(), + position: item.dataset.position, + salary: getSalary(item), + age: parseInt(item.dataset.age, 10), + }; + }); +} + +sortList(employeesList); + +getEmployees(employeesList);