Created
January 2, 2019 15:19
-
-
Save sealucky7/adebf792a02ff25f46382765a7af56d1 to your computer and use it in GitHub Desktop.
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
/* Напишите функцию которая вернет самый дорогой товар и его имя */ | |
var purchases = { | |
"meat": 1200, | |
"bread": 8, | |
"child food": 230, | |
"chips": null, | |
"juice": 240 | |
}; | |
function maxPrice(obj) { | |
var max = 0; | |
var nameProd = ''; | |
for (var key in obj) { | |
if( obj[key] > max ) { | |
max = obj[key]; | |
nameProd = key | |
} | |
} | |
return nameProd + ': ' + max | |
} | |
console.log(maxPrice(purchases)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment