JS_HOME_WORK/49-sort-array-of-objects/finish.js
2025-02-05 08:47:22 +01:00

44 lines
1.2 KiB
JavaScript
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/** ЗАДАЧА 49 - Сортировка объектов в массиве
*
* 1. Создайте функцию "sortProductsByPrice" с одним параметром "products"
*
* 2. Эта функция должна отсортировать входной массив товаров
* по цене каждого товара в порядке возрастания
* и вернуть отсортированный массив
*
* 3. Оригинальный массив должен остаться без изменений
*/
const inputProducts = [
{
title: 'Phone case',
price: 23,
quantity: 2,
category: 'Accessories',
},
{
title: 'Android phone',
price: 150,
quantity: 1,
category: 'Phones',
},
{
title: 'Headphones',
price: 78,
quantity: 1,
category: 'Accessories',
},
{
title: 'Sport Watch',
price: 55,
quantity: 2,
category: 'Watches',
},
]
// const sortedProducts = sortProductsByPrice(inputProducts)
// console.log(sortedProducts) // Массив отсортированных товаров
// console.log(inputProducts) // Оригинальный массив не должен измениться