listsAreDistinct(list1, list2 [, delim1] [, delim2])
Last updated June 25, 2003
Version: 1 | Requires: ColdFusion 5 | Library: StrLib
Description:
Given two lists, returns a boolean value telling you whether both lists have entirely different elements. In other words, no element in list 1 exists in list 2 and vice versa.
The comparison is case insensitive.
Return Values:
boolean
Example:
list1 = "a,b,c,d,e,f";
list2 = "g,h,i,j";
list3 = "K+A+I";
</cfscript>
<cfoutput>
Is list1 (<em>#list1#</em>) distinct from list2 (<em>#list2#</em>)?
<br />
#yesNoFormat(listsAreDistinct(list1,list2))#
<br /><br />
Is list1 (<em>#list1#</em>) distinct from list3 (<em>#list3#</em>)?
<br />
#yesNoFormat(listsAreDistinct(list1,list3,",","+"))#
<br /><br />
Is list3 (<em>#list3#</em>) distinct from list2 (<em>#list2#</em>)?
<br />
#yesNoFormat(listsAreDistinct(list3,list2,"+"))#
</cfoutput>
Parameters:
| Name | Description | Required |
|---|---|---|
| list1 | The first list | Yes |
| list2 | The second list | Yes |
| delim1 | The delimiter of the first list (default is comma) | No |
| delim2 | The delimiter of the second list (default is comma) | No |
Full UDF Source:
<cfscript>
/**
* Tells whether two lists have entirely distinct elements
*
* @param list1 The first list (Required)
* @param list2 The second list (Required)
* @param delim1 The delimiter of the first list (default is comma) (Optional)
* @param delim2 The delimiter of the second list (default is comma) (Optional)
* @return boolean
* @author Nathan Dintenfass (nathan@changemedia.com)
* @version 1, June 25, 2003
*/
function listsAreDistinct(list1,list2){
var delim1 = ",";
var delim2 = ",";
var ii = 0;
var array = "";
//deal with the optional delimiter arguments
switch(arrayLen(arguments)) {
case 3:
{
delim1 = arguments[3];
break;
}
case 4:
{
delim1 = arguments[3];
delim2 = arguments[4];
break;
}
}
//make list1 into an array for easy looping
array = listToArray(list1,delim1);
//loop through list1 checking for any matches in list2
for(ii = 1; ii LTE arrayLen(array); ii = ii + 1){
//if this element exists in list 2, return false
if(listFindNoCase(list2,array[ii],delim2))
return false;
}
//if we've gotten this far, the lists are distinct
return true;
}
</cfscript>
Search CFLib.org
Latest Additions
Tayo Akinmade added
arrayTrim
11 day(s) ago
Will Belden added
longTime
17 day(s) ago
James Sleeman added
quickSort
27 day(s) ago
Ben Forta added
GetHostAddress
30 day(s) ago
Top Rated
EksporSQLData
Rated 5.0, 16 time(s)
backupDatabase
Rated 5.0, 13 time(s)
indentXml
Rated 5.0, 10 time(s)
generateSsccAsn
Rated 5.0, 4 time(s)