# Part 5, Passes but not with correct intention

Hello magnificent human beings!!!

If you are here and able to clarify or help me solve this problem you will be the hero of this glorious Wednesday!

As stated in the the title, my code passes the test but does not perform the desired function! I have altered it a few times which still yields a pass but again not the functionality.

``````def alphabetize(arr, rev=false)
arr.sort! puts numbers
if rev==true
arr.reverse!
end
end
numbers = [ 0, 1, 2, 4, 6,10]
``````

So in the instances where I have altered the code in an attempt to get the functionality I have altered the methods argument to make [rev=true].

My reasoning behind this is that if the method argument states itâ€™s true and then I have an [if] statement saying DO THIS IF IT IS TRUE ; it should perform the desired task. Which it of course doesnâ€™t. So Lovely.

So Iâ€™ve spent a few moments altering it, as well as putting the fear of god into the syntax by highlighting it and holding my finger centimeters off the delete key for denying me the functionality Iâ€™m looking for all the while being reluctant to reverting back to part 1 of the lesson and simply copying the if/else/elsif format there; without luck.

I will be moving on from this task but would love clarification from You about how to fix this functionality error!

~Cheers!

3 Likes

I had a similar issue too. My code would pass but I didnâ€™t get a descending order of my values when I set rev=true. I just got the reverse of my values in order that they appeared in the array i.e. [1,6,5,3] would change to [3,5,6,1] rather than the desired [6,5,3,1]. So what I had to do was sort the array first then add an if/else statement to account for both conditions (rev=true, rev=false). This probably isnâ€™t the most elegant way to do it as the double â€śarr.sort!â€ť seems redudant, but it worked and thatâ€™s whatâ€™s important.

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

numbers = [1,4,2,3,6,5,3]
puts alphabetize(numbers,true)``````

Thank you very much , it was a moment That I was stuck. =)

I donâ€™t know if this lesson got debugged but i post my code which actually has the functionality.

def alphabetize(arr, rev=false)
arr.sort!
if rev == true
arr.reverse!
else
arr.sort!
end
end
numbers = [1, 15, 11, 4, 24]

alphabetize(numbers, true)
puts numbers