diff --git a/src/index.html b/src/index.html index f0f81a237..94265cede 100644 --- a/src/index.html +++ b/src/index.html @@ -11,6 +11,10 @@ rel="stylesheet" href="./styles/main.scss" /> +

List of employees

@@ -93,6 +97,5 @@

List of employees

Colleen Hurst - diff --git a/src/scripts/main.js b/src/scripts/main.js index a765fdb1d..f14fec9ce 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,40 @@ 'use strict'; -// write code here +// debugger; + +const employees = document.querySelectorAll('li'); +const listOfEmployees = document.querySelector('ul'); + +const sortedEmployees = sortList([...employees]); + +for (let i = 0; i < sortedEmployees.length; i++) { + listOfEmployees.append(sortedEmployees[i]); +} +getEmployees(sortedEmployees); + +function getEmployees(list) { + const rightList = []; + + for (let i = 0; i < list.length; i++) { + rightList.push({ + name: list[i].textContent.trim(), + position: list[i].dataset.position, + salary: list[i].dataset.salary, + age: list[i].dataset.age, + }); + } + + return rightList; +} + +function sortList(list) { + return list.sort((person1, person2) => { + return ( + parseSalary(person2.dataset.salary) - parseSalary(person1.dataset.salary) + ); + }); +} + +function parseSalary(salary) { + return Number(salary.replaceAll(/\D/g, '')); +}