Re: Array comparison returning nil

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