Ordering Your Library task №5


#1

Sorting With Control Flow

Great! Now we need to add the right logic to our method.

numbers = [1, 2, 3, 4, 5]
numbers.reverse!
puts numbers
  1. In the example above, we create an array called numbers .
  2. Then, we reverse the array. Like with .sort! , the exclamation mark means we modify the actual array.
  3. Finally, we print out 5 , 4 , 3 , 2 , and 1 .

After your .sort! call, add an if-else statement. If rev is true, call reverse! on arr , else return arr .

Keep your numbers array and the puts statement so that you can see your work in action!

in this example what is “rev”? what he doing ?
sorry for stupid question.


#2

the example is just some information about reversing, in the editor itself you should have a alphabetize function which has a rev parameter. You need to expand what alphabetize can do


#3

Thank you very much!


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.