CFLib.org – Common Function Library Project

ListRemoveDuplicates(lst[, delim])

Last updated August 22, 2005

author

Keith Gaughan

Version: 1 | Requires: CF5 | Library: StrLib

Description:
This is a faster alternative to the listDeleteDuplicates() currently in CFLib. It does the same thing, but uses a struct as a set so as to remove the duplicate elements. However, this loses the original order of the list.

Return Values:
Returns a string.

Example:

<cfoutput>#listRemoveDuplicates("a,list,with,a,few,duplicates")#</cfoutput>

Parameters:

Name Description Required
lst List to parse. Yes
delim List delimiter. Defaults to a comma. No

Full UDF Source:

/**
 * Remove duplicates from a list.
 * 
 * @param lst 	 List to parse. (Required)
 * @param delim 	 List delimiter. Defaults to a comma. (Optional)
 * @return Returns a string. 
 * @author Keith Gaughan (keith@digital-crew.com) 
 * @version 1, August 22, 2005 
 */
function listRemoveDuplicates(lst) {
    var i       = 0;
    var delim   = ",";
    var asArray = "";
    var set     = StructNew();

    if (ArrayLen(arguments) gt 1) delim = arguments[2];

    asArray = ListToArray(lst, delim);
    for (i = 1; i LTE ArrayLen(asArray); i = i + 1) set[asArray[i]] = "";

    return structKeyList(set, delim);
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson