Posted By

adrianparr on 03/04/10


Tagged

array copy match compare as3 same


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

tspitzr


AS3 Check if All the Values in Two Different Arrays are the Same


 / Published in: ActionScript 3
 

I'm not sure whether I should be using == (Equality) or === (Strict equality) here. I haven't been able to create a situation where it makes much difference. If you know better, feel free to leave me a comment.

  1. var array1:Array = new Array(1,2,3,4,5,6,7);
  2. var array2:Array = new Array(1,2,3,9,5,6,7);
  3.  
  4. function checkIfArraysMatch($arrayA:Array, $arrayB:Array):Boolean
  5. {
  6. var isMatch:Boolean = true;
  7. if($arrayA.length == $arrayB.length) {
  8. for (var i:int = 0; i<$arrayA.length; i++) {
  9. if ($arrayA[i] != $arrayB[i]) {
  10. isMatch = false;
  11. break;
  12. }
  13. }
  14. } else {
  15. isMatch = false;
  16. }
  17. return isMatch;
  18. }
  19.  
  20.  
  21. trace(checkIfArraysMatch(array1, array2));
  22.  
  23. // OUTPUT: false

Report this snippet  

You need to login to post a comment.