Skip to content

Instantly share code, notes, and snippets.

@sealucky7
Created January 2, 2019 15:19
Show Gist options
  • Save sealucky7/adebf792a02ff25f46382765a7af56d1 to your computer and use it in GitHub Desktop.
Save sealucky7/adebf792a02ff25f46382765a7af56d1 to your computer and use it in GitHub Desktop.
/* Напишите функцию которая вернет самый дорогой товар и его имя */
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