forked from as3/as3-utils
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcreateUniqueCopy.as
More file actions
41 lines (36 loc) · 912 Bytes
/
createUniqueCopy.as
File metadata and controls
41 lines (36 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package utils.array
{
/**
* Create a new array that only contains unique instances of objects
* in the specified array.
*
* Basically, this can be used to remove duplication object instances
* from an array
*
* @param arr The array which contains the values that will be used to
* create the new array that contains no duplicate values.
*
* @return A new array which only contains unique items from the specified
* array.
*
* @langversion ActionScript 3.0
* @playerversion Flash 9.0
* @tiptext
*/
public function createUniqueCopy(a:Array):Array
{
var newArray:Array = new Array();
var len:Number = a.length;
var item:Object;
for (var i:uint = 0; i < len; ++i)
{
item = a[i];
if (arrayContainsValue(newArray, item))
{
continue;
}
newArray.push(item);
}
return newArray;
}
}