Ordering Your Library - 5. Sorting with Control Flow/ Code, quick question

def alphabetize(arr, rev=false)
    rev ? arr.reverse! : nil

numbers = [3, 9, 3, 2, 1]

puts numbers

After looking at other users responses prior to this lesson, I learned to add the variable arr on line four. My question is, what is the purpose of this? It did not work when I did not add arr before. Any explanation?

1 Like

In Ruby, the last line of a function is the return value. It’s known as implicit return.

Interesting. Thank you @mtf, I appreciate it.

1 Like

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