Note that there are some explanatory texts on larger screens.

plurals
  1. POActionScript - Comparing & Removing Duplicates of Complex Arrays?
    primarykey
    data
    text
    <p>when comparing simple arrays, i use something like the following function to concatenate and remove duplicates:</p> <pre><code>//Merge public function merge(a1:Array, a2:Array):Array { var result:Array = a1.concat(a2); var dictionary:Dictionary = new Dictionary(); for each (var item:Object in result) dictionary[item] = true; result = new Array(); for (var key:Object in dictionary) result.push(key); dictionary = null; return result; } </code></pre> <p>however, this approach doesn't work on complex arrays.</p> <p>is there a well known algorithm, or is it even possible to write a function of recursion that can compare a <code>Vector.&lt;Object&gt;</code> with another? one that will always work even if the some objects being compared have additional key/value pairs?</p> <hr> <p><strong>[EDIT]</strong></p> <hr> <p>to be more clear, using a dictionary to determine if items in a simple array only works on primitive data types (int, number, string, etc.) or object references, so the above example works if it's passed 2 arrays resembling something like this:</p> <pre><code>var arr1:Array = new Array(1, 2, 3, 4, 5); var arr2:Array = new Array(8, 7, 6, 5, 4); </code></pre> <p>resulting in a merged array with the following values:</p> <pre><code>1, 2, 3, 8, 7, 6, 5, 4 </code></pre> <p>in contrast, i'm asking if it's possible to pass a function 2 complex arrays or <code>Vector.&lt;Object&gt;</code> all containing unique objects that may have identical key/value pairs and remove redundencies in the resulting <code>Vector.&lt;Object&gt;</code>. for example:</p> <pre><code>var vec1:Vector.&lt;Object&gt; = new Vector.&lt;Object&gt;(); vec1.push({city:"Montreal", country:"Canada"}); vec1.push({city:"Halifax", country:"Canada"}); var vec2:Vector.&lt;Object&gt; = new Vector.&lt;Object&gt;(); vec2.push({city:"Halifax", country:"Canada"}); vec2.push({city:"Toronto", country:"Canada"}); </code></pre> <p>merging the above 2 vector objects would result in the following vector by determining and removing objects with identical key/value pairs:</p> <pre><code>{city:"Montreal", country:"Canada"} {city:"Halifax", country:"Canada"} {city:"Toronto", country:"Canada"} </code></pre> <p>i'm searching for an algorithm which could handle the removal of these similar objects without having to know about their specific key/value names or how many key/value pairs there are within the object.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload