------=_Part_59199_2175089.1164246482502
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

I thought I was going to get to contribute, but then I got stuck.  I
installed the latest ruby, wrote a quick program that I thought would do it,
and it didn't.  So I expanded on the program, trying to figure out what was
going on, and now it's 20 lines long(mostly puts) and I *still* don't get
something (Beware - the single most basic code ever follows - it was
originally much nicer but then I got to trying to debug)

a = Array.new
a = %w{test test2 test3}
puts a
aSize = a.size
b = Array.new
b = %w{test3 nil test2 test}
bSize = b.size
puts 'size of b:' + bSize.to_s
puts b
puts 'size of a:' + aSize.to_s
if aSize = bSize
  aSorted= a.sort!
  bSorted= b.sort!
  if aSorted.eql?(bSorted)
    puts 'ssdd'
  else
    puts 'same size, different values'
  end
else
  puts 'not the same size'
end

>ruby array.rb
test
test2
test3
size of b:4
test3
nil
test2
test
size of a:3
same size, different values

What's wrong with if aSize = bSize?  That seems the most intuitive way to do
it to me... I mean, it's an integer... why is it going inside the loop at
all?
On 11/22/06, Daniel N <has.sox / gmail.com> 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]
>
> At first I thought of
> (( array1 | array2 ) - array1).size == 0
>
> but this does not take into account duplicate values and the should not
> equals do equal :(.  In fact I have not been able work out how to use any
> of
> the standard array, or Enumerable methods in such a way I can check if two
> arrays contain the same values as well as taking into account duplicates.
>
> Any pointers?
>
> Cheers
> Daniel
>
>

------=_Part_59199_2175089.1164246482502--