Here is a summary of the data returned in a shortened version:
var array =
[{
"response":
{
"itineraries":[
{
"price":
{
"totalPricePerPassenger":"104"
}
},
{
"price":
{
"totalPricePerPassenger":"102"
}
},
{
"price":
{
"totalPricePerPassenger":"103"
}
}
]
}
}];
My intention is to organize the returned data based on total price.
Below is the code I'm using for sorting and displaying the outcome:
function sort(a, b){
var a_price = a.response.itineraries.price.totalPricePerPassenger();
var b_price = b.response.itineraries.price.totalPricePerPassenger();
return ((a_price < b_price) ? -1 : ((a_price > b_price) ? 1 : 0));
}
var data = array.sort(sort);
console.log(data);
The output from the console.log indicates that the prices remain in their original sequence without any changes.
Any thoughts on why this might be occurring? Am I heading in the right direction?