The examples in the Adobe Array doc are not very intuitive…
If I have a Card object with properties str and visible, how do I rewrite this piece of code looking for a visible card with the certain str value?
FOUND:
for each (var str:String in newHand) {
for each (card in hand) {
if (card.visible && str == card.str)
continue FOUND;
}
// there is a new card - redraw the whole hand
redrawHand(owner);
break;
}
The
some(),every()(andforEach()) methods of theArrayclass have two parameters:callbacka function that is executed on each item, it should return true or false based on your criteriathisObjectis an optional object you can supply to the callback function, inside the function you can refer to the object with thethiskeyword. You can form a closure with the callback function if you omit this parameter.The signature of the callback function is as follows:
For your scenario, perhaps you could use the
some()method like this: