Forum: Ruby on Rails ruby array detect non linear data

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Me (Guest)
on 2009-01-15 03:47
(Received via mailing list)
Is there a way to detect in an array of say 1..500,  if some of the
numbers may be missing from the set.
Adam K. (Guest)
on 2009-01-15 05:43
(Received via mailing list)
If you have an array of 1 to 500 called 'a' and you wanted to know if
any were missing you could do:

a.uniq.size and if that doesn't equal 500 you are missing some.

If you need to know which ones are missing you could create a new
array of 1 to 500 and subtract the original

b = (1..500).to_a

b - a
This topic is locked and can not be replied to.