From 6c9fce72663cc94013f04937d072c1924ee4f51d Mon Sep 17 00:00:00 2001 From: Olga Bilokur Date: Fri, 3 Jul 2026 21:46:02 +0300 Subject: [PATCH] add task solution --- src/scripts/main.js | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index a765fdb1d..23302d317 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -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(), + position: item.dataset.position, + salary: getSalaryNumber(item.dataset.salary), + age: Number(item.dataset.age), + })); +} + +sortList(employeeList); + +getEmployees(employeeList);