forked from as3/as3-utils
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathremoveItem.as
More file actions
32 lines (27 loc) · 764 Bytes
/
removeItem.as
File metadata and controls
32 lines (27 loc) · 764 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
{
/**
Modifies original Array by removing all items that are identical to the specified item.
@param tarArray: Array to remove passed <code>item</code>.
@param item: Element to remove.
@return The amount of removed elements that matched <code>item</code>, if none found returns <code>0</code>.
@example
<code>
var numberArray:Array = new Array(1, 2, 3, 7, 7, 7, 4, 5);
trace("Removed " + ArrayUtil.removeItem(numberArray, 7) + " items.");
trace(numberArray);
</code>
*/
public function removeItem(tarArray:Array, item:*):uint
{
var i:int = tarArray.indexOf(item);
var f:uint = 0;
while (i != -1)
{
tarArray.splice(i, 1);
i = tarArray.indexOf(item, i);
f++;
}
return f;
}
}