Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save trycf/2a3762dabf10ad695a925d2bc8e55b09 to your computer and use it in GitHub Desktop.
Save trycf/2a3762dabf10ad695a925d2bc8e55b09 to your computer and use it in GitHub Desktop.
TryCF Gist
<cfscript>
// Simulated Query
all_employees = QueryNew("userdefined,hello,f", "varchar,varchar,varchar",
[
["test","pure text","takeMe"],
["2","number as varchar","takeMe"],
["03","leading zero","takeMe"],
[" 4 ","leading and trailing spaces","takeMe"],
["5 ","extra trailing spaces","takeMe"],
[" 6","extra leading spaces","takeMe"],
["aasdfadsf","adsfasdfasd","dontTakeMe"],
["165e73","scientific notation","takeMe"],
["1.5","decimal","takeMe"],
["1,5","comma-delimited (or non-US decimal)","takeMe"],
["1.0","valid decimal","takeMe"],
["1.","invalid decimal","takeMe"],
["1,000","number with comma","takeMe"]
]
) ;
//writedump(all_employees) ;
// Set up your return array.
retval = [] ;
// Filter your query (like WHERE clause)
filt = all_employees.filter( function(whereclause){ return ( whereclause.f == "takeMe"); } ) ;
//writedump(filt);
// Check your userDefined values and reformat if needed
filt.each(
function(r) {
retval.append(
ISNUMERIC(r.userDefined) ? right("00000000"&ltrim(rtrim((r.userdefined))),8) : r.userDefined
) ;
}
) ;
// Sort the array.
retval.sort("textnocase") ;
// Output our sorted array.
writedump(retval);
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment