Monday, February 27, 2012

Re: [Rails] Compare arrays

On Mon, Feb 27, 2012 at 4:51 PM, Rodrigo Ruiz <rodrigo.ruiz7@gmail.com> wrote:
> Ya, that is what I used (with sort), I was just wondering if there is a
> native way like:

No need to waste cycles like that. Array math will do fine.

> a = [1, 4, 2]
> b = [2, 1, 4]
>
> a.has_same_elements_as(b)

ruby-1.9.2-p290 :001 > a = [4,1,2]
=> [4, 1, 2]
ruby-1.9.2-p290 :002 > b = [1,2,4]
=> [1, 2, 4]
ruby-1.9.2-p290 :003 > b - a
=> []
ruby-1.9.2-p290 :004 > a - b
=> []


HTH,
Bill

--
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.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate