ColdFusion UDF Library - listDiff
December 16th, 2008
«« Back to ColdFusion Library
Category:
LIST
Description:
Returns an array (in order from first to last position) of all the differences between list1 and list2.
Parameters:
Returns:
(Array)
Requires:
Sample Use:
Copy to Clipboard
Category:
LIST
Description:
Returns an array (in order from first to last position) of all the differences between list1 and list2.
Parameters:
- list1 (List, required)
The first of the two lists you wish to compare item postions of. - list2 (List, required)
The second of the two lists you wish to compare item postions of. - limit (Numeric, Default: 0)
The maximum number of differences to return.
Values:- 0 : All differences.
- >0 : The ordinal number at which to limit the final array size.
- 0 : All differences.
- delimiter1 (String, Default: ,)
The delimiter of the first list. - delimiter2 (String, Default: ,)
The delimiter of the second list.
Returns:
(Array)
Requires:
Sample Use:
Copy to Clipboard
function listDiff(list1,list2){
var limit = -1;
var delimiter1 = ",";
var delimiter2 = ",";
var value = arrayNew(1);
var loop = 0;
var loopLimit = 0;
if (arrayLen(arguments) gte 3)limit = arguments[3];
if (arrayLen(arguments) gte 4)delimiter1 = arguments[4];
if (arrayLen(arguments) gte 5)delimiter2 = arguments[5];
loopLimit = min(listLen(list1,delimiter1),listLen(list2,delimiter2));
for (loop = 1; loop lte loopLimit; loop = incrementValue(loop)){
if (listGetAt(list1,loop,delimiter1) neq listGetAt(list2,loop,delimiter2))arrayAppend(value,loop);
if (limit gt 0 and arrayLen(value) eq limit)break;
};
if (limit eq 1 and arrayLen(value))value = value[1];
return value;
}
// http://www.programmers.org/index.php/coldfusion-udf-library/?ckey=315&function=listDiff



