deDupeArray(inputArray)
Last updated April 26, 2012
Version: 1 | Requires: ColdFusion 9 | Library: CFMLLib
Description:
I saw a function here for removing dupes from lists and queries, but not one for arrays. Here's one I've been using for a while.
Return Values:
Returns an array.
Example:
myArray = deDupeArray(myArray);
result: ["1","2","3","4"]
Parameters:
| Name | Description | Required |
|---|---|---|
| inputArray | Array to dedupe. | Yes |
Full UDF Source:
<cfscript>
/**
* Removes duplicate values from an array.
*
* @param inputArray Array to dedupe. (Required)
* @return Returns an array.
* @author Dave Anderson (the.one.true.dave.anderson@gmail.com)
* @version 1, April 26, 2012
*/
public array function deDupeArray(required array inputArray) {
local.arrList = arrayToList(inputArray);
local.retArr = inputArray;
for (local.i = arrayLen(inputArray);i gte 1;i=i-1) {
if (listValueCountNoCase(arrList,inputArray[i]) gt 1) {
arrayDeleteAt(retArr,i);
arrList = arrayToList(retArr);
}
}
return retArr;
}
</cfscript>
Search CFLib.org
Latest Additions
Adam Cameron added
composeDateTime
15 day(s) ago
Chris Weller added
convertQueryStri...
a while ago
Greg Nettles added
arrayDiff
a while ago
Nathan Dintenfass added
ArrayOfStructsSo...
a while ago
Top Rated
backupDatabase
Rated 5.0, 36 time(s)
indentXml
Rated 5.0, 10 time(s)
deAccent
Rated 5.0, 6 time(s)
countArbitraryDa...
Rated 5.0, 5 time(s)