What about something like this:

<cffunction 
        name="GetDiff"
        access="public"
        returntype="string"
        output="false"
        hint="Gets the difference between two lists based on index.">
        
        <!--- Define arguments. --->
        <cfargument 
                name="ListOne" 
                type="string" 
                required="true" 
                />
                
        <cfargument 
                name="ListTwo" 
                type="string" 
                required="true" 
                />
                
                
        <!--- Define the local scope. --->
        <cfset var LOCAL = StructNew() />
        
        
        <!--- Get the length of both lists. --->
        <cfset LOCAL.ListOneLength = ListLen( ARGUMENTS.ListOne ) />
        <cfset LOCAL.ListTwoLength = ListLen( ARGUMENTS.ListTwo ) />
        
        
        <!--- Set empty diff list. --->
        <cfset LOCAL.DiffList = "" />
        
        <!--- Loop over both lists. --->
        <cfloop
                index="LOCAL.Index"
                from="1"
                to="#Max( LOCAL.ListOneLength, LOCAL.ListTwoLength )#"
                step="1">
                
                
                <!--- Check to see if we have an element in list one to
check. --->
                <cfif (LOCAL.Index GT LOCAL.ListOneLength)>
                
                        <cfset LOCAL.DiffList = ListAppend( 
                                LOCAL.DiffList,
                                ListGetAt( ARGUMENTS.ListTwo,
LOCAL.Index )
                                ) />
                
                <cfelseif (LOCAL.Index GT LOCAL.ListTwoLength)>
                
                        <cfset LOCAL.DiffList = ListAppend( 
                                LOCAL.DiffList,
                                ListGetAt( ARGUMENTS.ListOne,
LOCAL.Index )
                                ) />
                        
                <cfelseif (
                        ListGetAt( ARGUMENTS.ListOne, LOCAL.Index ) NEQ 
                        ListGetAt( ARGUMENTS.ListTwo, LOCAL.Index )
                        )>
                        
                        <cfset LOCAL.DiffList = ListAppend( 
                                LOCAL.DiffList,
                                ListGetAt( ARGUMENTS.ListTwo,
LOCAL.Index )
                                ) />
                        
                </cfif>
                
        </cfloop>       
        
        
        <!--- Return the diff list. --->
        <cfreturn LOCAL.DiffList />     
</cffunction>


#GetDiff( 
        "1,2,4",
        "1,2,3,4"
        )# 



......................
Ben Nadel
Certified Advanced ColdFusion MX7 Developer
www.bennadel.com
 
Need ColdFusion Help?
www.bennadel.com/ask-ben/

-----Original Message-----
From: Joel Watson [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, March 06, 2007 10:41 AM
To: CF-Talk
Subject: Comparing two arrays or lists

I have two lists that I want to compare and be able to show the
resulting differences.  For example, if my first list has 1,2,3,4 and
the second has 1,2,4,4, I want to be able to output that "3" and "4" are
different.

What would be the best way of going about this?  I applied the
"arrayCompare" UDF from cflib, but it only outputs a bollean for the
entire comparison.  I would like to be able to compare on a more
detailed level and output the results.

Thanks!



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Deploy Web Applications Quickly across the enterprise with ColdFusion MX7 & 
Flex 2. 
Free Trial 
http://www.adobe.com/products/coldfusion/flex2/

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:271738
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to