From 3b3a2125553f59a4073f06f7e93a5293152146a6 Mon Sep 17 00:00:00 2001 From: pparys93 Date: Tue, 7 Jul 2026 21:19:47 +0200 Subject: [PATCH 1/2] add task solution --- src/scripts/main.js | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index a765fdb1d..62c62d3e8 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,37 @@ 'use strict'; -// write code here +function getEmployees(list) { + const items = list.children; + const employees = []; + + for (let i = 0; i < items.length; i++) { + const item = items[i]; + + employees.push({ + name: item.dataset.name, + position: item.dataset.position, + salary: parseInt(item.dataset.salary, 10), + age: parseInt(item.dataset.age, 10), + }); + } + + return employees; +} + +function sortList(list) { + const items = Array.from(list.children); + + items.sort((a, b) => { + const salaryA = parseInt(a.dataset.salary, 10); + const salaryB = parseInt(b.dataset.salary, 10); + + return salaryB - salaryA; + }); + + items.forEach((item) => list.appendChild(item)); +} + +const employeeList = document.querySelector('ul'); + +sortList(employeeList); +getEmployees(employeeList); From aa5004ee1169952522732b608e89865ff3fa12df Mon Sep 17 00:00:00 2001 From: pparys93 Date: Tue, 7 Jul 2026 22:42:10 +0200 Subject: [PATCH 2/2] add task solution(2) --- src/scripts/main.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index 62c62d3e8..2c68bb530 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,5 +1,9 @@ 'use strict'; +function getSalary(item) { + return parseInt(item.dataset.salary, 10); +} + function getEmployees(list) { const items = list.children; const employees = []; @@ -10,7 +14,7 @@ function getEmployees(list) { employees.push({ name: item.dataset.name, position: item.dataset.position, - salary: parseInt(item.dataset.salary, 10), + salary: getSalary(item), age: parseInt(item.dataset.age, 10), }); } @@ -22,8 +26,8 @@ function sortList(list) { const items = Array.from(list.children); items.sort((a, b) => { - const salaryA = parseInt(a.dataset.salary, 10); - const salaryB = parseInt(b.dataset.salary, 10); + const salaryA = getSalary(a); + const salaryB = getSalary(b); return salaryB - salaryA; });