Skip to content
Open
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
33 changes: 32 additions & 1 deletion src/scripts/main.js
Original file line number Diff line number Diff line change
@@ -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);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The function is named getEmployeers but the task requirement specifies it must be named getEmployees. This will cause test failures. Rename to getEmployees.

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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The return statement uses getEmployers instead of getEmployees. This needs to be renamed to match the required function name.

}
sortList(list);
getEmployees(list);
Loading