lundi 9 décembre 2019

ruby code, what is the code error below as shown?

Error message I get: undefined local variable or method `rev' for #

What is wrong with my if/else statement for the numbers method? Thank you for your help

This is my code:

def alphabetize(arr, rev=false)
  if rev
  arr.sort!{|item1, item2| item2<=>item1}
  else
  arr.sort!{|item1, item2| item1<=>item2}
  end
end

puts Array

numbers=[10, 12, 35, 17]
numbers.sort!
  if rev==true
    numbers.reverse! {|item1, item2, item3, item4|}
  else
    rev==false
    puts numbers
end

Aucun commentaire:

Enregistrer un commentaire