CFLib.org – Common Function Library Project

ListHasDupes(list[, delim][, caseCheck])

Last updated May 11, 2004

author

Mike Gillespie

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Pass a list to this function to evaluate if it contains duplicates.

Return Values:
Returns a boolean.

Example:

<cfset mylist="a,b,c,d,e,b">
<cfoutput>#ListHasDupes(mylist)#</cfoutput>

Parameters:

Name Description Required
list The list to check. Yes
delim List delimer. Defaults to a comma. No
caseCheck Determines if checking should be case-sensitive. Defaults to false. No

Full UDF Source:

/**
 * Returns true if list has duplicate elements.
 * 
 * @param list      The list to check. (Required)
 * @param delim      List delimer. Defaults to a comma. (Optional)
 * @param caseCheck      Determines if checking should be case-sensitive. Defaults to false. (Optional)
 * @return Returns a boolean. 
 * @author Mike Gillespie (mike@striking.com) 
 * @version 1, May 11, 2004 
 */
function listHasDupes(list) {
    var arr=arraynew(1);
    var caseCheck=false;
    var delim=",";
    var i = 1;
    
    if (arrayLen(arguments) gt 1) delim = arguments[2];    
    if (arrayLen(arguments) gt 2) CaseCheck=Arguments[3];
    
    if(not caseCheck) list = lcase(list);
    
    arr=listToArray(list,delim);
    
    for (;i lte arraylen(arr);i=i+1 ) {
        if (listValueCount(list,arr[i],delim) gt 1) return true;
    }
    return false;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson