Skip to content

Instantly share code, notes, and snippets.

@VitorLuizC
Last active January 16, 2018 20:27
Show Gist options
  • Select an option

  • Save VitorLuizC/42e9cb753235b61ae40e0a86f9878a18 to your computer and use it in GitHub Desktop.

Select an option

Save VitorLuizC/42e9cb753235b61ae40e0a86f9878a18 to your computer and use it in GitHub Desktop.
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