I don't believe that will do it, since the arrays aren't actually equal:
I believe Arrays (for the purposes of object comparison) are only equal
if they contain the same elements in the same order.

-- 
Maciek Sakrejda
Truviso, Inc.
http://www.truviso.com

-----Original Message-----
From: Scot <[EMAIL PROTECTED]>
To: Maciek Sakrejda <[EMAIL PROTECTED]>
Subject: Re: What is the best way to compare two arrays element by
element ignoring the o
Date: Fri, 22 Feb 2008 19:10:17 -0000

Would ObjectUtil.compare(object1, object2); do the job?

http://livedocs.adobe.com/flex/2/langref/mx/utils/ObjectUtil.html#compare()



--- In flexcoders@yahoogroups.com, Maciek Sakrejda <[EMAIL PROTECTED]> wrote:
>
> Extra points for higher-order function, although that is going to be
> O(n^2) (unless Array.indexOf() has a weird implementation). If you've
> got really, really big arrays (or are doing this in a tight loop) and
> you have O(n) memory to spare, you could consider building a hashmap of
> the values in Array a, and then walking Array b and checking if each
> element is in the hashmap:
> 
> var differs:Boolean = (a.length != b.length);
> if (!differs) {
>   var aContents = new Object();
>   a.forEach(function(item:Object, index:int, array:Array):void {
>     aContents[item] = true;
>   });
>   differs = b.some(function(item:Object, index:int, array:Array):Boolean
> {
>     return aContents[item] == null;
>   });
> }
> 
> For small-ish arrays, though, I would expect your solution to be faster
> than mine (I won't define 'small-ish', since I would honestly be pulling
> a number out of my--err, out of thin air).
> 
> Also, neither your solution nor mine handles the case where the same
> item is in one array twice (yours fails for dupes in a and mine for
> dupes in b).
> 
> -- 
> Maciek Sakrejda
> Truviso, Inc.
> http://www.truviso.com
> 
> -----Original Message-----
> From: Sergey Kovalyov <[EMAIL PROTECTED]>
> Reply-To: flexcoders@yahoogroups.com
> To: flexcoders@yahoogroups.com
> Subject: [flexcoders] What is the best way to compare two arrays element
> by element ignoring the order?
> Date: Fri, 22 Feb 2008 15:37:56 +0200
> 
> What is the best way to compare two arrays element by element ignoring
> the order? My solution:
> 
> var differs : Boolean =
>  (a.length != b.length) ||
>  a.some(
>   function(item : Object, index : int, array : Array) : Boolean {
>    return (b.indexOf(item) == -1);
>   });
> 
> May be the better solution exists?
>





Reply via email to