Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6384163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:44:28+00:00 2026-05-25T02:44:28+00:00

when comparing simple arrays, i use something like the following function to concatenate and

  • 0

when comparing simple arrays, i use something like the following function to concatenate and remove duplicates:

//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;
}

however, this approach doesn’t work on complex arrays.

is there a well known algorithm, or is it even possible to write a function of recursion that can compare a Vector.<Object> with another? one that will always work even if the some objects being compared have additional key/value pairs?


[EDIT]


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:

var arr1:Array = new Array(1, 2, 3, 4, 5);
var arr2:Array = new Array(8, 7, 6, 5, 4);

resulting in a merged array with the following values:

1, 2, 3, 8, 7, 6, 5, 4

in contrast, i’m asking if it’s possible to pass a function 2 complex arrays or Vector.<Object> all containing unique objects that may have identical key/value pairs and remove redundencies in the resulting Vector.<Object>. for example:

var vec1:Vector.<Object> = new Vector.<Object>();
vec1.push({city:"Montreal", country:"Canada"});
vec1.push({city:"Halifax", country:"Canada"});

var vec2:Vector.<Object> = new Vector.<Object>();
vec2.push({city:"Halifax", country:"Canada"});
vec2.push({city:"Toronto", country:"Canada"});

merging the above 2 vector objects would result in the following vector by determining and removing objects with identical key/value pairs:

{city:"Montreal", country:"Canada"}
{city:"Halifax", country:"Canada"}
{city:"Toronto", country:"Canada"}

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:44:28+00:00Added an answer on May 25, 2026 at 2:44 am

    Sure you can, you can build a similar example with any type of Vector:

         public function mergeObjectVectors(v1:Vector.<Object>,                      
                                            v2:Vector.<Object>):Vector.<Object>
         {
            var dictionary:Dictionary = new Dictionary();
            var concat:Vector.<Object> = v1.concat(v2);
            var result:Vector.<Object> = new Vector.<Object>();
    
            for each(var i:Object in concat)
            {
                if (!dictionary[i])
                {
                    dictionary[i] = true;
                    result.push(i);
                }
            }           
    
            return result;
        } 
    

    However if you plan on accepting vectors of any type, it’s different:

            public function testing():void
            {
                 var v1:Vector.<Object> = new Vector.<Object>();
                 v1.push({name:"Object 1"});
                 v1.push({name:"Object 2"});
    
                 // Vector w duplicates
                 var v2:Vector.<Object> = new Vector.<Object>();
                 var o:Object = {name:"Object 3"};                 
                 v2.push(o);
                 v2.push(o);
                 v2.push(o);
    
                 var resultVector:Vector.<Object> = mergeAnything(v1, v2, Class(Vector.<Object>));
                 var resultArray:Array = mergeAnything(v1, v2, Array);
                 var resultObject:Object = mergeAnything(v1, v2, Object);
            }
    
    
            public function mergeAnything(o1:Object, o2:Object, resultClass:Class):*
            {
    
                var dictionary:Dictionary = new Dictionary();
                var result:Object = new resultClass();
    
                var i:int;
                for each(var o:Object in o1)
                {
                   if (!dictionary[o])
                   {
                      dictionary[o] = true;
                      result[i++] = o;
                   }
                }   
    
                for each(o in o2)
                {
                   if (!dictionary[o])
                   {
                      dictionary[o] = true;
                      result[i++] = o;
                   }
                }
    
                return result;
            }
    

    The first example will be more resource-efficient.


    EDIT:
    This should do it, try it with your example:

         public function mergeObjectVectors(v1:Vector.<Object>, v2:Vector.<Object>):Vector.<Object>
        {
            var concat:Vector.<Object> = v1.concat(v2);
            var result:Vector.<Object> = new Vector.<Object>();
    
            var n:int = concat.length;
            loop:for (var i:int = 0; i < n; i++)
            {   
                var objectToAdd:Object = concat[i];
    
                var m:int = result.length;
                for (var j:int = 0; j < m; j++)
                {
                    var addedObject:Object = result[j];
                    if (this.areObjectsIdentical(objectToAdd, addedObject))
                    {
                        continue loop;
                    }
                }
                result.push(objectToAdd);
            }           
    
            return result;
        } 
    
        private function areObjectsIdentical(o1:Object, o2:Object):Boolean
        {
            var numComparisons:int = 0;
    
            for (var s:String in o1)
            {
                numComparisons++;
                if (o1[s] != o2[s])
                {
                    return false;
                }
            }                   
            for (s in o2)
            {
                numComparisons--;
            }
    
            return !numComparisons;     
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Comparing string in C# is pretty simple. In fact there are several ways to
Comparing LinkedLists and Arrays while also comparing their differences with sorted and unsorted data
I have hundreds of thousands of NumPy boolean arrays that I would like to
I'm trying to compare a character array against a string like so: const char
This is a simple code that should return true or false after comparing each
Put simply, I want to subtract one array from another. The arrays are arrays
How can I enable the use of VLAs, variable length arrays as defined in
An interesting (and probably simple) problem for you all, I have two arrays, and
I'm wondering if my method below of comparing an array of strings (or any
So the title is somewhat misleading... I'll keep this simple: I'm comparing these two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.