You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
690 B
29 lines
690 B
"use strict"; |
|
|
|
function main(formName) { |
|
let result = document.getElementById("result"); |
|
|
|
let arr = [ |
|
{name: "Кола", price: 5}, |
|
{name: "Вода", price: 1}, |
|
{name: "Чай", price: 2}, |
|
{name: "Коктейль", price: 10}, |
|
{name: "Мохито", price: 8} |
|
]; |
|
|
|
if (item instanceof Array) { |
|
result.textContent = "Ошибка: arr должен быть массивом!"; |
|
return; |
|
} |
|
|
|
result.textContent = "Результат: " + sortDrinks(arr); |
|
} |
|
|
|
function sortDrinks(arr) { |
|
let result = []; |
|
|
|
arr.sort( (first, second) => first.price > second.price ? 1 : -1 ); |
|
arr.forEach( elem => result.push(elem.name + " - " + elem.price) ); |
|
|
|
return result.join(", "); |
|
}
|
|
|