From 06721b92f5eaeaf99be62ae88233af23320c9086 Mon Sep 17 00:00:00 2001 From: ILLYA SMYK Date: Thu, 28 May 2026 16:40:44 +0200 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..bdec23a4d 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,33 @@ 'use strict'; -// write code here +const list = [...document.querySelectorAll('li')]; + +function getSalary(li) { + return Number(li.dataset.salary.slice(1).replaceAll(',', '')); +} + +function sortList(items) { + items.sort((a, b) => { + return getSalary(b) - getSalary(a); + }); + + const ul = document.querySelector('ul'); + + for (const item of items) { + ul.append(item); + } +} + +function getEmployees(items) { + return items.map((item) => { + return { + name: item.textContent.trim(), + position: item.dataset.position, + salary: getSalary(item), + age: Number(item.dataset.age), + }; + }); +} + +sortList(list); +getEmployees(list);