ColdFusion remove duplicate component in a list

I use this simple script for removing duplicate component in a list. below is the script


<cfoutput>
    <cfset List = "one,two,three,four,five,one,three">
    <cfset tempList = "">
    <cfloop list="#List#" index="i">
        <cfif not ListFind(tempList, i)>
            <cfset tempList = ListAppend(tempList, i)>
        </cfif>
    </cfloop>
    #tempList#>
</cfoutput>

just loop over the list and check weather new list contains the “index” component or not, if doesn’t contains, append it in that new list

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s