Return to Snippet

Revision: 13969
at May 14, 2009 10:07 by sidneydekoning


Initial Code
// removes all duplicate items from an array

/**
* @method removeDuplicates
* @description removes duplicate items from the array
* @param haystack:Array - the array from which to remove any duplicates
*/
public static function removeDuplicates(haystack:Array):Array{

	var dict:Dictionary = new Dictionary( true );
	var output:Array = new Array( );
	var item:*;
	var total:int = haystack.length;
	var pointer:int = 0;
	for(pointer; pointer < total ; pointer++) {
		item = haystack[pointer];
		if(dict[item] == undefined) {
			output.push( item );
			dict[item] = true;
		}
	}
	return output;     
}

Initial URL

                                

Initial Description

                                

Initial Title
Remove duplicates from Array

Initial Tags

                                

Initial Language
ActionScript 3