# Re: Array comparison returning nil

**URL:** <https://www.ruby-forum.com/t/re-array-comparison-returning-nil/76283>\
**Category:** Ruby\
**Created:** [March 3, 2006, 4:24pm UTC](https://www.ruby-forum.com/t/re-array-comparison-returning-nil/76283 "2006-03-03T16:24:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 3, 2006, 4:24pm UTC](https://www.ruby-forum.com/t/re-array-comparison-returning-nil/76283/1 "2006-03-03T16:24:32Z")

</div>

Could it be that some of the elements in your arrays cannot be  
compared,  
like “a” and 1 ?

You can help this by mapping all these elements to numbers or strings,  
which  
can be sorted,  
as in this example

a = [“three”,3, “four”,4]  
c = [“ten”,10,“eleven”,11]  
b=a.sort{ |x,y| x.to\_s \<=\> y.to\_s}\<=\>c.sort { |x,y| x.to\_s \<=\> y.to\_s}  
puts “result is #{b}”

which gives a result -1, since 3 is smaller than 10.

Best regards,

Axel
