mardi 21 mars 2017

Ruby sorting even and odd numbers issue

I'm learning Ruby and just started with the sorting. Trying to sort the array like this: [1,3,5,2,4,6] and I'm don't really understand what is wrong with the code. Any help would be appreciated!

[1,2,3,4,5,6].sort do |x,y|
  if x.odd? and y.odd?
    0
  elsif x.odd?
    -1
  else
     1
end  
  if (x.odd? && y.odd?) or (x.even? && y.even?)
  x <=> y
end 
end

Aucun commentaire:

Enregistrer un commentaire