Ruby array detect non linear data


#1

Is there a way to detect in an array of say 1…500, if some of the
numbers may be missing from the set.


#2

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