Using ColdFusion to sort an multi-dimensional array based on a "Price per sq. ft" field from high to low.
It has been in production and worked in testing, but a case has come up that has yielded strange, unsorted results. I also ran this on the CFDOCS site using their ArraySort code and got the same, incorrect sort results.
As you can see the results are not even really sorted.
Here's my code:
figures = [
{name='carl',price='117.5'},
{name='fen',price='116.4'},
{name='joe',price='86.3'}
];
arraySort(figures, function (a, b){
return compare(b.price, a.price);
});
writeDump(figures);
Results:
NAME joe
PRICE 86.3
NAME carl
PRICE 117.5
NAME fen
PRICE 116.4
It should be sorted in this order: 117.5, 116.4, 86.3.
I believe it's sorting in a way that makes 86.3 appear greater than the rest because it starts with an 8? I also tried without the quotes and got the wrong results as well.
I ran this same code on cfdocs.org and got the same, wrong results.
Am I doing something incorrectly in my sort parameters or on the callback?
Thank you!