728x90
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let salaries = { | |
"John": 100, | |
"Pete": 300, | |
"Mary": 250 | |
}; | |
function topSalary(salaries) { | |
let maxSalaryName = ''; | |
let maxSalary = 0; | |
for(const [ username, salary ] of Object.entries(salaries)) { | |
if(salary > maxSalary) { | |
maxSalaryName = username; | |
maxSalary = salary; | |
} | |
} | |
return { maxSalaryName, maxSalary }; | |
} | |
const topSalaryInfo = topSalary(salaries); | |
console.log('topSalaryName: ', topSalaryInfo.maxSalaryName); | |
console.log('topSalary: ', topSalaryInfo.maxSalary); |
'Algorithm > JavaScript(Node.js)' 카테고리의 다른 글
The Modern JS Tutorial: Date and Time: show a weekday (0) | 2021.11.17 |
---|---|
The Modern JS Tutorial: Date and Time: create a date (0) | 2021.11.15 |
The Modern JS Tutorial: Destructuring Assignment: destructuring assignment (0) | 2021.10.25 |
The Modern JS Tutorial: WeakMap and WeakSet: store read dates (0) | 2021.10.20 |
The Modern JS Tutorial: WeakMap and WeakSet: Store "unread" flags (0) | 2021.10.20 |