arrayDiff(smallerArray, biggerArray)
Last updated March 13, 2007
Version: 1 | Requires: ColdFusion 5 | Library: DataManipulationLib
Description:
This function compares 2 one-demensional arrays (a & b) with simple values and returns an array with the values found in one array (a) but not in the other (b).
Return Values:
Returns an array.
Example:
aSmaller = arrayNew(1);
aSmaller[1] = 'a';
aSmaller[2] = 'b';
aBigger = arrayNew(1);
aBigger[1] = 'a';
aBigger[2] = 'c';
aBigger[3] = 'b';
aBigger[4] = 'd';
</cfscript>
Smaller Array:
<cfdump var="#aSmaller#"><br />
Bigger Array:
<cfdump var="#aBigger#"><br />
Difference between the two:
<cfset aDifferences = arrayDiff(aSmaller,aBigger)>
<Ccfdump var="#aDifferences#">
Parameters:
| Name | Description | Required |
|---|---|---|
| smallerArray | First array. | Yes |
| biggerArray | Second array. | Yes |
Full UDF Source:
<cfscript>
/**
* Compares two arrays (with simple values) and returns the difference between the two.
*
* @param smallerArray First array. (Required)
* @param biggerArray Second array. (Required)
* @return Returns an array.
* @author Greg Nettles (gregnettles@gmail.com)
* @version 1, March 13, 2007
*/
function arrayDiff(smallerArray,biggerArray) {
var i = "";
var result = arrayNew(1);
var s = arrayToList(arguments.smallerArray);
for (i=1;i lte arrayLen(arguments.biggerArray); i=i+1) if (listFind(s, arguments.biggerArray[i]) is 0) arrayAppend(result, arguments.biggerArray[i]);
return result;
}
</cfscript>
Search CFLib.org
Latest Additions
Tayo Akinmade added
arrayTrim
10 day(s) ago
Will Belden added
longTime
15 day(s) ago
James Sleeman added
quickSort
25 day(s) ago
Ben Forta added
GetHostAddress
28 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)