to have a problem if there are more than one objects with the same second highest salary value. But if that's not your concern then you can do something like this:
let secondHighestSalary = (salaries) => {
let noHighest = salaries.filter(s => s.salary < Math.max(...salaries.map(s => s.salary)));
return noHighest.reduce((p,c) => p.salary > c.salary ? p : c);
}
If that's your concern then:
let secondHighestSalary = (salaries) => {
let noHighest = salaries.filter(s => s.salary < Math.max(...salaries.map(s => s.salary)));
let secondHighest = noHighest.reduce((p,c) => p.salary > c.salary ? p.salary : c.salary);
return salaries.filter(s => s.salary === secondHighest);
}
Really thanks bro 👍
Обсуждают сегодня