Created
January 11, 2019 03:42
-
-
Save trycf/2130fbceeffe07cbaae88703ebd6b409 to your computer and use it in GitHub Desktop.
TryCF Gist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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