Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save trycf/2130fbceeffe07cbaae88703ebd6b409 to your computer and use it in GitHub Desktop.
Save trycf/2130fbceeffe07cbaae88703ebd6b409 to your computer and use it in GitHub Desktop.
TryCF Gist
<cfscript>
figures = [
{name='carl',price='117.5'},
{name='fen',price='116.4'},
{name='joe',price='86.3'},
{name='alan',price='1117.3'}
];
// TEXT comparison
arraySort(figures, function (a, b){
local.num = compare(a.price, b.price);
local.text = local.num == -1 ? " less than "
: (local.num == 0 ? " equals " : " greater than");
writeOutput("<br> "& a.price &" "& local.text &" "& b.price &" => "& local.num );
return local.num ;
});
// NUMERIC comparison - ASCENDING Order
arraySort(figures, function (a, b){
return (a.price < b.price) ? -1 : (a.price == b.price ? 0 : 1);
});
writeDump(figures);
// NUMERIC comparison - DESCENDING Order
arraySort(figures, function (a, b){
return (b.price < a.price) ? -1 : (b.price == a.price ? 0 : 1);
});
writeDump(figures);
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment