Posted By

sidneydekoning on 05/14/09


Tagged


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

macKaminski
muoto
IsoJon


Remove duplicates from Array


 / Published in: ActionScript 3
 

  1. // removes all duplicate items from an array
  2.  
  3. /**
  4. * @method removeDuplicates
  5. * @description removes duplicate items from the array
  6. * @param haystack:Array - the array from which to remove any duplicates
  7. */
  8. public static function removeDuplicates(haystack:Array):Array{
  9.  
  10. var dict:Dictionary = new Dictionary( true );
  11. var output:Array = new Array( );
  12. var item:*;
  13. var total:int = haystack.length;
  14. var pointer:int = 0;
  15. for(pointer; pointer < total ; pointer++) {
  16. item = haystack[pointer];
  17. if(dict[item] == undefined) {
  18. output.push( item );
  19. dict[item] = true;
  20. }
  21. }
  22. return output;
  23. }

Report this snippet  

You need to login to post a comment.