Calvin Ward wrote:

> For flexibility, how about this: ListFirst(ListSort(numbers,'numeric'))

If we were talking about a lower-level language, I'd warn against that
way of doing it. On average, ListSort() takes O(nlogn) to sort a list,
whereas scanning the list with <cfloop> as below will be done in O(n)
time, which is faster. The only advantage that using ListSort() has is
that it's precompiled into Java.

Come to think of it, a linear scan will still be faster regardless,
unless you're dealing with CF5 or below.

The best and safest way to scan an unsorted list for the maximum number
would be:

<!---
     Using the first element as our default max ensures that if the
     list contains only negative numbers, it will still work properly.
     This is my one improvement over Ewok's method.
--->
<cfset max = ListFirst(numbers)>
<cfloop index="i" list="#numbers#">
     <cfif i gt max>
         <cfset max = i>
     </cfif>
</cfloop>

K.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:203069
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to