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
- In the example above, we create an array called
- Then, we reverse the array. Like with
.sort!, the exclamation mark means we modify the actual array.
- Finally, we print out
.sort! call, add an
if-else statement. If
rev is true, call
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.