Hey not bad. Neat approach.

-----Original Message-----
From: Keith Gaughan [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, April 20, 2005 7:21 AM
To: CF-Talk
Subject: Re: take duplicate out of a list

CFDEV wrote:

> Hi, is there an easy way to take duplicate out of a list or do I have to
> loop trough the list and create a new list with all elements and check if
> they are already in the new list before inserting them?

Here's a neat method:

<cfset lst = "a,list,with,with,duplicate,elements">
<!--- We shall be using a struct as a set! --->
<cfset set = StructNew()>
<cfloop index="elem" list="#lst#">
     <cfset set[elem] = "">
</cfloop>
<cfset lst = StructKeyList(set)>

Et, voil�!

After all, a map is just a set with values attached to each one of the
elements. For example, the HashSet in Java is internally implemented
using a HashMap.

K.



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Find out how CFTicket can increase your company's customer support 
efficiency by 100%
http://www.houseoffusion.com/banners/view.cfm?bannerid=49

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:203639
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=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to