CFLib.org – Common Function Library Project

deDupeArray(inputArray)

Last updated April 26, 2012

author

Dave Anderson

Version: 1 | Requires: CF9 | 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 = ["1","2","1","3","1","4"];
myArray = deDupeArray(myArray);

result: ["1","2","3","4"]

Parameters:

Name Description Required
inputArray Array to dedupe. Yes

Full UDF Source:

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