diff --git a/src/scripts/main.js b/src/scripts/main.js index a765fdb1d..63d9d0dbc 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,34 @@ 'use strict'; -// write code here +const list = document.querySelector('ul'); + +function getSalary(item) { + return Number(item.dataset.salary.replaceAll(',', '').replace('$', '')); +} + +function sortList(ul) { + const items = [...ul.children]; + + items.sort((a, b) => { + return getSalary(b) - getSalary(a); + }); + ul.append(...items); +} + +function getEmployees(ul) { + const items = [...ul.children]; + const employers = []; + + items.forEach((item) => { + employers.push({ + name: item.textContent.trim(), + position: item.dataset.position, + salary: getSalary(item), + age: Number(item.dataset.age), + }); + }); + + return employers; +} +sortList(list); +getEmployees(list);