# Ruby array detect non linear data

**URL:** <https://www.ruby-forum.com/t/ruby-array-detect-non-linear-data/157763>\
**Category:** Rails\
**Created:** [January 15, 2009, 2:47am UTC](https://www.ruby-forum.com/t/ruby-array-detect-non-linear-data/157763 "2009-01-15T02:47:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 15, 2009, 2:47am UTC](https://www.ruby-forum.com/t/ruby-array-detect-non-linear-data/157763/1 "2009-01-15T02:47:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 15, 2009, 4:43am UTC](https://www.ruby-forum.com/t/ruby-array-detect-non-linear-data/157763/2 "2009-01-15T04:43:38Z")

</div>

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
