Hi --

On Thu, 23 Nov 2006, Morton Goldberg wrote:

> On Nov 22, 2006, at 8:04 PM, Daniel N wrote:
>
>> I want to check to see if two arrays contain the same values.
>> That is, are they the same array but not in the same order.
>> 
>> Example
>> equal
>> [1,2,3,4,"abc"] should equal [2,3,1,"abc",4]  and all the other different
>> orders that are possible
>> 
>> This should not be equal
>> [1,2,3] and [1,1,2,3]
>> [1,2,3,nil] and [nil, nil, nil, 1,2,1,3,2]
>
> In general, if the arrays can contain arbitrary elements, this is a difficult 
> problem. If the elements themselves can be arrays, you will want to start by 
> duplicating the two arrays and flattening the duplicates. If the duplicates 
> are not the same size, you're done. If they are the same size, you will need 
> to define a notion of canonical order (basically a sort order that is 
> applicable to all elements) and transform both arrays into canonical order -- 
> this can be the hard part. Then you can make an element by element 
> comparison.

I'm not sure about the flattening.  If you have:

   [1,2,[3,4],5]

and

   [1,[2,3],4,5]

as I understand it, the comparison should fail, because the arrays
contain different elements, not the same elements in possibly
different order.  I guess we'd need a ruling from Daniel.


David

-- 
                   David A. Black | dblack / wobblini.net
Author of "Ruby for Rails"   [1] | Ruby/Rails training & consultancy [3]
DABlog (DAB's Weblog)        [2] | Co-director, Ruby Central, Inc.   [4]
[1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com
[2] http://dablog.rubypal.com    | [4] http://www.rubycentral.org