Skip to content

Update solution.md #3848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
let salaries = {
John: 100,
Pete: 300,
Mary: 250,
};
function topSalary(salaries = {}) {
const nth = Object.keys(salaries).length; // getting object property names in array and then getting array length.
if (nth == 0) return null; // if array is empty return null

const salaryData = []; // creating new array to store salaries only.

for (let [employ, salary] of Object.entries(salaries)) salaryData.push(salary); // storing salary in salaryData array.

return `Hightes paying salary is => ${Math.max(...salaryData)}`; // calculating max salary number with the help of Math.max()
}
console.log((topSalary(salaries)))