Bird
0
0

Which of the following is the correct syntax to reverse an array arr in Ruby?

easy📝 Syntax Q12 of 15
Ruby - Arrays
Which of the following is the correct syntax to reverse an array arr in Ruby?
Aarr.reverse!
Barr.reverse[]
Creverse.arr()
Darr.reverse()!
Step-by-Step Solution
Solution:
  1. Step 1: Identify the correct method call

    The method to reverse an array in place is reverse! called on the array object.
  2. Step 2: Check syntax correctness

    Only arr.reverse! is valid Ruby syntax; others are incorrect method calls or misplaced symbols.
  3. Final Answer:

    arr.reverse! -> Option A
  4. Quick Check:

    reverse! modifies array in place [OK]
Quick Trick: Use reverse! to reverse array in place [OK]
Common Mistakes:
  • Using parentheses incorrectly
  • Placing exclamation mark after parentheses
  • Calling reverse as a standalone function

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes