forked from as3/as3-utils
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathretainItems.as
More file actions
32 lines (29 loc) · 765 Bytes
/
retainItems.as
File metadata and controls
32 lines (29 loc) · 765 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
package utils.array
{
/**
Retains only the specified items in an Array.
@param tarArray: Array to remove non specified items from.
@param items: Array of elements to keep.
@return Returns <code>true</code> if the Array was changed as a result of the call; otherwise <code>false</code>.
@example
<code>
var numberArray:Array = new Array(1, 2, 3, 7, 7, 7, 4, 5);
ArrayUtil.retainItems(numberArray, new Array(2, 4));
trace(numberArray);
</code>
*/
public function retainItems(tarArray:Array, items:Array):Boolean
{
var removed:Boolean = false;
var l:uint = tarArray.length;
while (l--)
{
if (items.indexOf(tarArray[l]) == -1)
{
tarArray.splice(l, 1);
removed = true;
}
}
return removed;
}
}