Ruby on Rails Monday, February 27, 2012

On Mon, Feb 27, 2012 at 5:29 PM, Rodrigo Ruiz <rodrigo.ruiz7@gmail.com> wrote:
> Yes, duplicates are important.

Assuming nil entries may also be important...

ruby-1.9.2-p290 :016 > a = [2,1,4,nil,1]
=> [2, 1, 4, nil, 1]
ruby-1.9.2-p290 :017 > b = [1,2,2,4,nil,nil]
=> [1, 2, 2, 4, nil, nil]
ruby-1.9.2-p290 :018 > a.compact.uniq - b.compact.uniq
=> []
ruby-1.9.2-p290 :019 > a
=> [2, 1, 4, nil, 1]
ruby-1.9.2-p290 :020 > b
=> [1, 2, 2, 4, nil, nil]

see http://ruby-doc.org/core-1.9.3/Array.html for other interesting
Array methods.

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.

No comments:

Post a Comment