diff --git a/README.md b/README.md index 294f077fb..ef566311b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ 1. Replace `` with your Github username in the link - - [DEMO LINK](https://.github.io/js_task_parse_list_DOM/) + - [DEMO LINK](https://LiliiaVol.github.io/js_task_parse_list_DOM/) 2. Follow [this instructions](https://mate-academy.github.io/layout_task-guideline/) - Run `npm run test` command to test your code; - Run `npm run test:only -- -n` to run fast test ignoring linter; diff --git a/src/scripts/main.js b/src/scripts/main.js index a765fdb1d..c340a899f 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,35 @@ 'use strict'; -// write code here +const ul = document.querySelector('ul'); +const li = [...document.querySelectorAll('li')]; + +const changeToNum = (str) => { + return Number(str.split('$')[1].replaceAll(',', '')); +}; + +const sortList = (list, ulList) => { + ulList.append( + ...list.sort( + (el1, el2) => + changeToNum(el2.dataset.salary) - changeToNum(el1.dataset.salary), + ), + ); +}; + +const getEmployees = (list) => { + const result = []; + + list.forEach((element) => { + result.push({ + name: element.textContent.trim(), + position: element.dataset.position, + salary: element.dataset.salary, + age: element.dataset.age, + }); + }); + + return result; +}; + +sortList(li, ul); +getEmployees(li);