/ Published in: ActionScript 3
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// 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; }