I have came up with this simple snippet.
var a:Array = new Array( 1,2,3,4,5,6,7,8);
var b:Array = new Array( 6,7,8 ) //<<<These items need to be removed from a
public function removeItemsFromAThatAreListedInB(a:Array, b:Array )
{
for ( var i=0 ; i< a.length ;i++)
{
for ( var j=0 ; j< b.length ; j++)
{
if ( (a[i]) == (b[j]) )
{
a.splice(i,1)
}
}
}
}
Just wanna make sure, if someone has a better “optimized” and “speedier” way to do the same ?
Most of these answers look to be for JavaScript. Since the pasted code looks to be AS3 I think you may want something like this.
Try using Array.indexOf instead of a second loop
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Array.html#indexOf%28%29