Hi I just have an array of names (strings) in flash, and I want to make sure that any duplicates from the array are removed, or at least that a function is performed only once per reocurring value in the array.
相关问题
- garbage collection best practices
- Should I wait for Flash Player 10.1 or go with Fla
- How to load flex swf from flash?
- FlashDevelop Haxe (Flash) debugger
- Converting Date with Time in PST into UTC format
相关文章
- Are there any benefits when using final in AS3?
- Trace on Chrome/Browser console
- as3 ByteArray to Hex (binary hex representation)
- getElementById not working in Google Chrome extens
- Libraries for text animation in Flex / Actionscrip
- About Collision detection alghorithms in AS3
- How to upload BitmapData to a server (ActionScript
- Manage resources to minimize garbage collection ac
Here's another way to do it, possibly a little nicer to look at:
This probably isn't the most performant way of doing it, @prototypical's method is probably much more efficient, but it's the theory that you asked for :)
Here is a more elegant way of removing duplicates:
Same approach for an array:
Good answers!
I've checked a few of them, and have worse results in contrast to my. It's quite simple:
Statistics with my data:
Dict approach: 8946ms, 8718ms, 8936ms
Obj approach: 8800ms, 8809ms, 8769ms
My old approach: 8723ms, 8599ms, 8700ms
This approach: 6771ms, 6867ms, 6706ms
I voted for Adam's option, but then I found this, and it looks to me this could be better performance wise still?
The idea here is that you loop backwards through the array, and since indexOf gives you the first occurring index, you can check the found index with the current index(i) and remove if not the same.
would @prototypical s response not give issues if the sourceArray[i] matches sourceArray[j] more than once because the length of sourceArray would be shorter if an element has been .splice()d out of it?
I've rewritten this method to count from the end so that this doesn't happen
More cat skinning: