Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
rel="stylesheet"
href="./styles/main.scss"
/>
<script
defer
src="scripts/main.js"
></script>
</head>
<body>
<h1>List of employees</h1>
Expand Down Expand Up @@ -93,6 +97,5 @@ <h1>List of employees</h1>
Colleen Hurst
</li>
</ul>
<script src="scripts/main.js"></script>
</body>
</html>
39 changes: 38 additions & 1 deletion src/scripts/main.js
Original file line number Diff line number Diff line change
@@ -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)
);
});
Comment on lines +30 to +35

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing requirement: Create a separate helper function to convert salary string to number. Currently the conversion replaceAll(/\D/g, '') is embedded directly in the sort function. Extract this logic into a helper function as required by the task description.

}

function parseSalary(salary) {
return Number(salary.replaceAll(/\D/g, ''));
}
Loading