What's a nice way to merge two sorted arrays in ActionScript (specifically ActionScript 3.0)? The resulting array should be sorted and without duplicates.
相关问题
- How to get the maximum of more than 2 numbers in V
- Faster loop: foreach vs some (performance of jsper
- Convert Array to custom object list c#
- pick a random item from a javascript array
- Newtonsoft DeserializeXNode expands internal array
相关文章
- Numpy matrix of coordinates
- PHP: Can an array have an array as a key in a key-
- Accessing an array element when returning from a f
- How can I convert a PHP function's parameter l
- How to make a custom list deserializer in Gson?
- Recursively replace keys in an array
- React Native - Dynamic Image Source
- js if any value in array is under or over value
Please follow the below step to get your answer:
Returned "ansArr" will be sorted and without duplicate merged array of two array.
Then for the "merge" use concat. exemple :
To merge (concatenate) arrays, use
.concat()
.Below are two examples of how you can concatenate arrays and remove duplicates at the same time.
More convenient way: (you can use
ArrayUtil.createUniqueCopy()
from as3corelib)Slightly faster way: (you can loop through the arrays yourself and use
Array.indexOf()
to check for duplicates)Using Array.indexOf to detect duplicates is going to be painfully slow if you have a List containing a large number of elements; a far quicker way of removing duplciates would be to throw the contents of the Array into a Set after concatenating them.
If your program makes heavy use of Collections then if may be prudent to make use of one of the many AS3 Collections frameworks out there which provide a simple interface for manipulating data and will always take the optimal approach when it comes to the implementation.
This is kind of an simple algorithm to write. I would be surprised if there were a more direct way to do this in Actionscript.