Bird
0
0

What does the Ruby method reverse! do when called on an array?

easy📝 Conceptual Q2 of 15
Ruby - Arrays
What does the Ruby method reverse! do when called on an array?
AReverses the array in place, modifying the original
BSorts the array in descending order
CReturns a new reversed array without changing the original
DSorts the array in ascending order
Step-by-Step Solution
Solution:
  1. Step 1: Understand the difference between reverse and reverse!

    reverse returns a new reversed array without changing the original, while reverse! reverses the array in place.
  2. Step 2: Identify the effect of reverse!

    reverse! modifies the original array by reversing its elements.
  3. Final Answer:

    Reverses the array in place, modifying the original -> Option A
  4. Quick Check:

    reverse! modifies original array = true [OK]
Quick Trick: reverse! changes original array, reverse returns new [OK]
Common Mistakes:
MISTAKES
  • Thinking reverse! returns new array
  • Confusing reverse! with sort!
  • Expecting reverse! to sort array

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes