The maximal salary
الأهمية: 5
There is a salaries
object:
let salaries = {
"John": 100,
"Pete": 300,
"Mary": 250
};
Create the function topSalary(salaries)
that returns the name of the top-paid person.
- If
salaries
is empty, it should returnnull
. - If there are multiple top-paid persons, return any of them.
P.S. Use Object.entries
and destructuring to iterate over key/value pairs.
function topSalary(salaries) {
let maxSalary = 0;
let maxName = null;
for(const [name, salary] of Object.entries(salaries)) {
if (maxSalary < salary) {
maxSalary = salary;
maxName = name;
}
}
return maxName;
}