ActionScript 3: Check Array for Compliance

If you have an array with six numbers, say:

public var check:Array = new Array[10,12,5,11,9,4]; 

or

 public var check:Array = new Array[10,10,5,11,9,4]; 

How do you check compliance (pairs?)

+4
source share
2 answers

Array class has an indexOf method :

function indexOf(searchElement:*, fromIndex:int = 0):int

Searches for an element in an array using strict equality (===) and returns the index position of the element.

Parameters

  • searchElement:* - the element to find in the array.
  • fromIndex:int (default = 0) - the location in the array from which to start the search for the element.

Returns

  • int is the index position based on the null element in the array. If searchElement not found, the return value is -1.
+6
source

Got (I think). The following is used:

 public var match:Array = [10,12,5,10,9,4]; checkArray(match); private function checkArray(check:Array) { var i:int; var j:int; for (i= 0; i < check.length; i++) { for (j= i+1; j < check.length; j++) { if (check[i] === check[j]) { trace(check[i] + " at " + i + " is a match with "+check[j] + " at " + j); } } } } 
0
source

All Articles