All the latest and ... well, the latest anyway.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3950 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package com.threerings.util {
|
||||
|
||||
/**
|
||||
* Contains methods that should be in Array, but aren't.
|
||||
*/
|
||||
public class ArrayUtil
|
||||
{
|
||||
/**
|
||||
* Remove the first instance of the specified element from the array.
|
||||
*/
|
||||
public static function removeFirst (arr :Array, element :Object) :void
|
||||
{
|
||||
removeImpl(arr, element, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the last instance of the specified element from the array.
|
||||
*/
|
||||
public static function removeLast (arr :Array, element :Object) :void
|
||||
{
|
||||
arr.reverse();
|
||||
removeFirst(arr, element);
|
||||
arr.reverse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all instances of the specified element from the array.
|
||||
*/
|
||||
public static function removeAll (arr :Array, element :Object) :void
|
||||
{
|
||||
removeImpl(arr, element, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of remove methods.
|
||||
*/
|
||||
private static function removeImpl (
|
||||
arr :Array, element :Object, firstOnly :Boolean) :void
|
||||
{
|
||||
for (var ii :int = 0; ii < arr.length; ii++) {
|
||||
if (arr[ii] === element) {
|
||||
arr.splice(ii--, 1);
|
||||
if (firstOnly) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user