Nice. Did you know that as of version 8 CF now supports i++ ? As well as a ton of other operators it didn't before.
++, --, %, +=, -=, *=, /=, %=, &&, ||, and ! and in cfscript you also have ==, !=, <. <=, >, >=. http://www.bennadel.com/blog/741-Learning-ColdFusion-8-All-Hail-The-New-Operator.htm On Thu, Oct 14, 2010 at 8:42 PM, Gerald Guido <[email protected]>wrote: > > <cfscript> > > function ListReturnDuplicates(list) { > var i = 1; > var delimiter = ','; > var returnValue1 = ''; > var tmpList = list; > > if(arrayLen(arguments) GTE 2) delimiter = arguments[2]; > list = ListToArray(list, delimiter); > for(i = 1; i LTE ArrayLen(list); i = i + 1) if(ListValueCount(tmpList, > list[i]) GT 1 and not listFind(returnValue1,list[i],delimiter)) > returnValue1 > = ListAppend(returnValue1, list[i], delimiter); > > return returnValue1; > } > </cfscript> > > On Thu, Oct 14, 2010 at 8:34 PM, Michael Grant <[email protected]> wrote: > > > > > > > > > > > > Instead of nested loops, use a struct for the found values: > > > > > > > Oh, I like that! I don't know why I always seem to default to arrays > > instead > > of structs. Must be some baggage from Allaire days or something? > > > > The extra good news is that it also seems to be faster to use your method > > Sean, from about two to ten times as fast. You need to be running about > > 5000 > > iterations to see any real difference, but it seems faster nonetheless. > > > > Thanks for that! I love (read: LOVE) learning better ways. > > > > Here's my test code. (I know, I know, tick count isn't a real test, but > > it's > > at least a pseudo useful metric) > > > > > > > > <cfparam name="form.fieldnames" > > > > > default="input1,input2,input3,input4,input5,input6,input7,input8,input9,input10,input11,input12,input13,input14,input15,input16,input17,input18,input19,input20" > > /> > > <cfparam name="form.input1" default="value1" /> > > <cfparam name="form.input2" default="value2" /> > > <cfparam name="form.input3" default="value3" /> > > <cfparam name="form.input4" default="value4" /> > > <cfparam name="form.input5" default="value5" /> > > <cfparam name="form.input6" default="value6" /> > > <cfparam name="form.input7" default="value7" /> > > <cfparam name="form.input8" default="value8" /> > > <cfparam name="form.input9" default="value9" /> > > <cfparam name="form.input10" default="value10" /> > > <cfparam name="form.input11" default="value11" /> > > <cfparam name="form.input12" default="value12" /> > > <cfparam name="form.input13" default="value13" /> > > <cfparam name="form.input14" default="value14" /> > > <cfparam name="form.input15" default="value15" /> > > <cfparam name="form.input16" default="value16" /> > > <cfparam name="form.input17" default="value17" /> > > <cfparam name="form.input18" default="value18" /> > > <cfparam name="form.input19" default="value19" /> > > <cfparam name="form.input20" default="value20" /> > > > > <cfset iter = 5000> > > > > <cfset timeStart = getTickCount()> > > <cfloop from="1" to="#iter#" index="a"> > > <cfset foundArray = arrayNew(1)> > > <cfloop list="#form.fieldNames#" index="x"> > > <cfset wasFound = false /> > > <cfloop from="1" to="#arrayLen(foundArray)#" index="y"> > > <cfif foundArray[y] EQ form[x]> > > <cfset wasFound = true /> > > </cfif> > > </cfloop> > > <cfif wasFound> > > <!--- logic to handle a duplicate found ---> > > <cfelse> > > <cfset ArrayAppend(foundArray,form[x])> > > </cfif> > > </cfloop> > > </cfloop> > > <cfoutput>nested loop: #getTickCount()-timeStart#<br /></cfoutput> > > > > <cfset timeStart = getTickCount()> > > <cfloop from="1" to="#iter#" index="a"> > > <cfset found = structNew()> > > <cfloop list="#form.fieldNames#" index="x"> > > <cfset wasFound = false /> > > <cfif STRUCTKEYEXISTS(found,form[x])> > > <cfset wasFound = true /> > > </cfif> > > <cfif wasFound> > > <!--- logic to handle a duplicate found ---> > > <cfelse> > > <cfset found[form[x]] = form[x]> > > </cfif> > > </cfloop> > > </cfloop> > > <cfoutput>structKeyExists: #getTickCount()-timeStart#<br /></cfoutput> > > > > > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:338220 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

