Last active
January 16, 2018 20:27
-
-
Save VitorLuizC/42e9cb753235b61ae40e0a86f9878a18 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const employees = [ | |
| { | |
| name: 'Renan', | |
| salary: 1000.00 | |
| }, | |
| { | |
| name: 'Vitor', | |
| salary: 980.50 | |
| }, | |
| { | |
| name: 'Marcos', | |
| salary: 2500.00 | |
| } | |
| ] | |
| const getSalaryDiff = (employeeA, employeeB) => employeeA.salary - employeeB.salary | |
| const getSalarySortedEmployees = (employees) => { | |
| const salarySortedEmployees = [ ...employees ].sort(getSalaryDiff).reverse() | |
| return salarySortedEmployees | |
| } | |
| const getSalariesSum = (employees) => { | |
| const salariesSum = employees.reduce((sum, employee) => { | |
| return sum + employee.salary | |
| }, 0) | |
| return salariesSum | |
| } | |
| // ordeno e pego os 10 primeiros | |
| const first = getSalarySortedEmployees(employees).splice(0, 10) | |
| // somo os salários dos 10 primeiros | |
| const sum = getSalariesSum(first) | |
| console.log(sum) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment