Posted By

quan on 12/30/09


Tagged

array compare


Versions (?)

Compare two array


 / Published in: ActionScript 3
 

Consider the following piece of code which compares two arrays to find which elements exist in outerArray that do not exist in innerArray:

  1. var outerArray:Array = ["coffee", "juice", "water", "beer"];
  2. var innerArray:Array = ["liquor", "beer", "wine", "juice"];
  3.  
  4. for each (var foo:String in outerArray)
  5. {
  6. var found:Boolean = false;
  7. for each (var bar:String in innerArray)
  8. {
  9. if (foo == bar)
  10. {
  11. found = true;
  12. }
  13. }
  14. if (!found)
  15. {
  16. trace(foo);
  17. }
  18. }

Report this snippet  

You need to login to post a comment.