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;
}
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