Jump to content

The ultimate community for Ruby on Rails developers.


Photo

why does this not work

rails

  • Please log in to reply
2 replies to this topic

#1 roelof

roelof

    Passenger

  • Members
  • 4 posts

Posted 24 May 2014 - 12:03 PM

For a assignment at CodeAcademy I have the this script.

def alphabetize(arr, rev=false)
arr.sort!
if rev == true 
    arr.reverse!
end
puts arr
end

numbers = [ 5, 1,3,8] 

alphabetize(numbers, rev = true) 


But now I see this error message :

Oops, try again. It looks like your method doesn't default to alphabetizing an array when it doesn't receive a second parameter. 

Can anyone explain to me where I go wrong ?

 

Roelof

 



#2 palytoxin

palytoxin

    Signalman

  • Members
  • 10 posts

Posted 24 May 2014 - 03:44 PM

what's your ruby version?

 

i'm using ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]

it's work fine. 

 

BTW:

you try to change it

alphabetize(numbers, rev = true) 

===>

alphabetize(arr:numbers, rev: true) 

 or 

alphabetize(numbers, true)


#3 roelof

roelof

    Passenger

  • Members
  • 4 posts

Posted 24 May 2014 - 04:52 PM

I have to check which version CodeAcademy uses.

I have tested it all and they all gives the right answers.

So I think there is a bug in CodeAcademy.







Also tagged with one or more of these keywords: rails

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users