Copy link to clipboard
Copied
Hi
I have the following
<cfset thelist = "1,5,8,11,22,76,6,143,147">
How do i get the highest and lowest number out of that string?
Thanking you in advance for your help!
Regards
Delon
Use the very well named ListToArray() function .. and definitely bookmark the online documentation 😉 The functions by category view is invaluable.
http://livedocs.adobe.com/coldfusion/8/functions-pt0_13.html
Copy link to clipboard
Copied
One approach might be to convert the list to an array and use arrayMax/arrayMin. Assuming the list contains valid numbers, of course.
Copy link to clipboard
Copied
Hi
Thanks for the reply.
Ok, so my next question would be... how do i convert that list to an array?
Excuse my ignorance. Im quite new to it!
Copy link to clipboard
Copied
Use the very well named ListToArray() function .. and definitely bookmark the online documentation 😉 The functions by category view is invaluable.
http://livedocs.adobe.com/coldfusion/8/functions-pt0_13.html
Copy link to clipboard
Copied
<cfset sortedList = listSort(thelist, "numeric", "Asc")>
min: <cfoutput>#listFirst(sortedList)#</cfoutput><br>
max: <cfoutput>#listLast(sortedList)#</cfoutput>
Copy link to clipboard
Copied
If you take this approach (which is a fine one), don't forget to build error-tolerance into the process, by means of the <cftry> and <cfcatch> tags.
It is reasonable to assume that, from time to time, this routine may be handed un-processable inputs, which will result in various kinds of exceptions being "thrown." Your application, however, should not "fall flat on its face" when this occurs. Instead, it should "catch" them and respond to the situation in some intelligent way.
This is, by the way, a perfectly-appropriate validation technique for cases like this. You know that "ka-ka might occur," whether it is highly-likely or not-at-all. Instead of spending gobs of computing-cycles checking every single input against "what might go wrong," you simply post someone in the outfield with a big glove. He might spend weeks with nothing to do, but each and every time "ka-ka occurs," he will catch the ball.
Copy link to clipboard
Copied
ka-ka occurs
Quite philosophical for French readers.