Ruby on Rails Monday, February 27, 2012

Ya, that is what I used (with sort), I was just wondering if there is a native way like:


a = [1, 4, 2]
b = [2, 1, 4]

a.has_same_elements_as(b)


Although now I think sort is the best way.

Thank you all for replying.


On Mon, Feb 27, 2012 at 7:28 PM, Hassan Schroeder <hassan.schroeder@gmail.com> wrote:
On Mon, Feb 27, 2012 at 2:04 PM, Rodrigo Ruiz <rodrigo.ruiz7@gmail.com> wrote:
> Hi, does anyone know how to compare to arrays not considering their order?

> if I compare [1, 4, 2] with [4, 1, 2], this should return true.

ruby-1.9.2-p290 :004 > [4,1,2] == [1,4,2]
 => false
ruby-1.9.2-p290 :005 > [4,1,2].sort == [1,4,2].sort
 => true

Like that?

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
http://about.me/hassanschroeder
twitter: @hassan

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment