It's New Year time and you have prepared a list of special gifts for your colleagues. Each gift is represented as an object with two properties: name
(a string) and price
(a number). Your task is to write a function sortGifts
that sorts these gift objects:
price
.name
.The function should return a new sorted array without modifying the original input.
Given the following input:
[
{ "name": "Coffee Mug", "price": 15 },
{ "name": "Notebook", "price": 10 },
{ "name": "Pen", "price": 10 },
{ "name": "Desk Organizer", "price": 25 }
]
The sorted output should be:
[
{ "name": "Notebook", "price": 10 },
{ "name": "Pen", "price": 10 },
{ "name": "Coffee Mug", "price": 15 },
{ "name": "Desk Organizer", "price": 25 }
]
Happy New Year and good luck coding!