In Coldfusion how do you order a list alphabetically then numerically -
In Coldfusion how do you order a list alphabetically then numerically -
say have next list:
<cfset mylist = "1a,2b,3c,aa,bb,cc" >
how sort list "aa,bb,cc,1a,2b,3c"? in other words, want starts number @ end of list , in order of number starts with.
this work if on cf10+.
<cfscript> values = listtoarray("1a,2b,3c,aa,bb,cc"); arraysort(values, function(e1, e2) { var diff = val(e1) - val(e2); if(diff != 0) homecoming diff; homecoming e1 < e2 ? -1 : 1; }); writedump(values); </cfscript>
run: http://www.trycf.com/scratch-pad/pastebin?id=kky9y2nn
update
but since you're using cf9:
<cfscript> function customsort(input) { var sorted = false; while (!sorted) { sorted = true; (var = 1; < arraylen(input); i++) { var e1 = input[i]; var e2 = input[i + 1]; var diff = val(e1) - val(e2); if (diff == 0 ? e1 > e2 : diff > 0) { arrayswap(input, i, + 1); local.sorted = false; } } } homecoming input; } values = listtoarray("1a,2b,3c,3a,aa,bb,cc"); writedump(customsort(values)); </cfscript>
run: http://www.trycf.com/scratch-pad/pastebin?id=xk3fqv9t
coldfusion coldfusion-9 cfml
Comments
Post a Comment