<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>
<Below this line, add a link to the EXACT exercise that you are stuck at.>
I am stuck with Ordering Your library exercise.
<In what way does your code behave incorrectly? Include ALL error messages.>
def alphabetize(arr, rev = false)
arr.sort!
if rev
arr.sort!
else
arr.reverse!
end
end
numbers = [5, 1, 3, 8]
puts alphabetize(numbers)
```
I got an error massage. Where I am wrong?
<do not remove the three backticks above>
@stanisa ,
What is the exact Oops- or Error-message
and
why are you sorting the Array BEFORE the IF ELSE statement…
I have the same problem I fixed it like this
def alphabetize(arr,rev=false)
if rev
arr.reverse!
else
arr.sort!
end
end
numbers=[1,3,2,5,4,68]
puts alphabetize(numbers,false)
maxcct
August 5, 2016, 7:55pm
#4
Because the lesson instructions say “After your .sort! call, add an if statement.” (Emphasis added.) The lesson seems to be broken, insofar as you can only get it to pass by using an inefficient structure.
3 Likes
ktsein
August 7, 2016, 11:51am
#5
def alphabetize (arr, rev=false)
if rev == false
arr.sort!
else
arr.reverse!
end
end
numbers = [3, 2, 4, 1, 5]
alphabetize(numbers)
puts "#{alphabetize(numbers)}"
this seems to work. ```
type or paste code here
Yes, it works.
Thanks for help.
yes the instructions are quiet misleading.
we need to accept array.
if rev is false , then we should not REVERSE it. just sort it in ascending order
if rev is true then REVERSE the array with reverse! method.
i was getting correct output but also with error generated.
1 Like
system
closed
August 23, 2016, 3:54pm
#8
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.