On November 3rd, as we prepare to celebrate the upcoming holiday season, you are tasked with a special sorting challenge. Imagine you have a list of holiday gifts. Each gift is represented as an object with the following properties:
name
(string): The name of the gift.weight
(number): The weight of the gift.cost
(number): The cost of the gift.Your task is to write a function sortGifts
that sorts the array of gifts with the following criteria:
An array of gift objects. For example:
[
{ "name": "Toy Car", "weight": 2, "cost": 20 },
{ "name": "Doll", "weight": 1, "cost": 15 },
{ "name": "Board Game", "weight": 2, "cost": 25 }
]
A sorted array of gift objects meeting the criteria above.
Given the input above, your function should return:
[
{ "name": "Doll", "weight": 1, "cost": 15 },
{ "name": "Board Game", "weight": 2, "cost": 25 },
{ "name": "Toy Car", "weight": 2, "cost": 20 }
]
Below you will find the language-agnostic starter code stubs for your implementation.
Happy coding and enjoy the holiday spirit!