Hello guys! does anyone know how to solve this? Thank you very much!!
Order an array of numbers with bubble sort
New array must be returned
The algorithm is going to receive an array of objects like this:
{
name: "Notebook",
price: 1200,
review: 8
}
this objects should be sorted in the way the next parameters indicate “firstOrd”, “secondOrd”
secondOrd is used in the cases firstOrd have the same value
var array = [
{name: "Notebook", price: 1200, review: 8},
{name: "Smartphone", price: 300, review: 9},
{name: "TV", price: 700, review: 1},
{name: "PS5", price: 1100, review: 7}
]
First example
magicSort(array, "price") should be:
[
{name: "Smartphone", price: 300, review: 9},
{name: "TV", price: 800, review: 1},
{name: "Notebook", price: 1200, review: 8}
{name: "PS5", price: 1200, review: 7}
]
2nd example
magicSort(array, "price", "review") should be
[
{name: "Smartphone", price: 300, review: 9},
{name: "TV", price: 800, review: 1},
{name: "PS5", price: 1200, review: 7},
{name: "Notebook", price: 1200, review: 8}
]
function magicSort(array, firstOrd, secondOrd){ }