Code Lab

Top salary

EasyObjects5 min

Write a function topSalary(salaries). In the object salaries each key is a name and each value is a salary.

Return the name of the person with the highest salary. If the object is empty, return null.

Examples

topSalary({ John: 100, Pete: 300, Mary: 250 })

Returns 'Pete'

topSalary({})

Returns null

topSalary({ Ann: 0 })

Returns 'Ann'

A salary of 0 counts too.

Source

Loading the editor...
  1. InputtopSalary({ John: 100, Pete: 300, Mary: 250 })
    Expected'Pete'
  2. InputtopSalary({})
    Expectednull
  3. InputtopSalary({ Ann: 0 })
    Expected'Ann'

Hidden tests run on Submit.